gpt4 book ai didi

python - 对图像使用 Python OpenCV Moments 函数

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:01 26 4
gpt4 key购买 nike

我尝试在灰度图像上使用 Python opencv 函数 Moments(),但我收到以下 TypeError:

>>> img = cv.LoadImage('example_image.jpg', cv.CV_LOAD_IMAGE_GRAYSCALE)
>>> moments = cv.Moments(img)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Argument '' must be CvSeq, CvArr, or a sequence of numbers
>>>

我相信这种用法是正确的,因为它在 opencv 文档中得到了演示 here ,其中 GetHuMoments() 使用 Moments() 的结果。

我相信我已经正确安装了 opencvnumpy,因为我已经成功地将它们用于许多其他事情,并且我在 OS X 10.6 和 Red 上都遇到过这种情况帽子 6.

同样的问题是posed in the opencv user group ,但我不想按照回复指示先将图像转换为轮廓。

最佳答案

看起来您需要强制从 IplImage 转换为 cvMat

之前有个问题“Capture Image as Array with Python OpenCV”

Capture Image as Array with Python OpenCV

例如对我来说

>>> mm=cv.Moments(img)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Argument '' must be CvSeq, CvArr, or a sequence of numbers
>>> mat=cv.GetMat(img)
>>> mm=cv.Moments(mat)
>>> mm.m00
181428.0

关于python - 对图像使用 Python OpenCV Moments 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7309899/

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