使用 Python OpenCV Moments 函数处理图像
我尝试在灰度图像上使用 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 文档中所演示的那样 此处,其中 GetHuMoments()
使用 Moments()
的结果。
我相信我已经正确安装了 opencv 和 numpy,因为我已经成功地将它们用于许多其他事情,并且我在 OS X 10.6 和 Red Hat 6 上都遇到了这种情况。
I am trying to use the Python opencv function Moments()
on a grayscale image, but I receive the following 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
>>>
I am confident this usage is correct as it is demonstrated in the opencv docs here, where GetHuMoments()
uses the results from Moments()
.
I believe I have opencv and numpy installed correctly, as I have been successfully using them for many other things, and I encounter this on both OS X 10.6 and Red Hat 6.
The same question is posed in the opencv user group, but I don't want to convert the image to a contour first as the reply instructs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您需要强制从 IplImage 转换为 cvMat
之前有一个问题“使用 Python OpenCV 将图像捕获为数组”
使用 Python OpenCV 将图像捕获为数组
例如对我来说
Looks like you need to force conversion from IplImage to cvMat
There was a previous question "Capture Image as Array with Python OpenCV"
Capture Image as Array with Python OpenCV
e.g for me
您使用的是哪个版本的 python 和 opencv?我在 python 2.6.6 和 opencv 2.1.0 上得到工作结果
Which python and opencv version are you using? I am getting working results on python 2.6.6 and opencv 2.1.0