gpt4 book ai didi

python - 如何对OpenCV calcHist()直方图进行polyfit()?

转载 作者:行者123 更新时间:2023-12-02 17:36:17 27 4
gpt4 key购买 nike

我有这样的事情:

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
我对此很陌生,但似乎我缺少一些简单的东西?

最佳答案

调用np.linspace时,这似乎是一个较小的语法错误。正确的语法是

x = np.linspace(interval_start, interval_end, number_of_points)

所以在你的情况下
x = np.linspace(0, 1, histr.shape[0])

关于python - 如何对OpenCV calcHist()直方图进行polyfit()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50457074/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com