我有这样的事情:
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
import numpy.polynomial.polynomial as poly
img = cv.imread('SomeImage.jpg')
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv.calcHist([img],[i],None,[32],[0,256])
plt.plot(histr,color = col)
plt.xlim([0,32])
x = np.linspace(0,histr.shape[0],1); # <== ERROR HERE
poly.polyfit(x, histr, 4)
我收到以下错误:
File "/Users/case/anaconda2/lib/python2.7/site-packages/numpy/polynomial/polynomial.py", line 1438, in polyfit
raise TypeError("expected x and y to have same length")
TypeError: expected x and y to have same length
我对此很陌生,但似乎我错过了一些简单的东西?
答案 0 :(得分:1)
调用np.linspace
时看起来像是一个小的语法错误。正确的语法是
x = np.linspace(interval_start, interval_end, number_of_points)
所以在你的情况下,那将是
x = np.linspace(0, 1, histr.shape[0])