opencv getImage() 错误
今天我用 simplecv python 接口包装了 opencv。在阅读官方 SimpleCV Cookbook 后,我能够成功 加载、保存 和 操作图像。因此,我知道该库正在正确加载。
但是,根据 使用摄像头、Kinect 或虚拟摄像头相机 标题 我运行一些命令失败。特别是,mycam = Camera()
有效,但 img = mycam.getImage()
产生了以下错误:
In [35]: img = mycam.getImage().save()
OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize, file /home/jordan/OpenCV-2.2.0/modules/core/src/array.cpp, line 1237
---------------------------------------------------------------------------
error Traceback (most recent call last)
/home/simplecv/<ipython console> in <module>()
/usr/local/lib/python2.7/dist-packages/SimpleCV-1.1-py2.7.egg/SimpleCV/Camera.pyc in getImage(self)
332
333 frame = cv.RetrieveFrame(self.capture)
--> 334 newimg = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
335 cv.Copy(frame, newimg)
336 return Image(newimg, self)
error: Array should be CvMat or IplImage
我在 HP TX2500 平板电脑上运行 Ubuntu Natty。它有一个内置网络摄像头(CyberLink Youcam?)以前有人见过这个错误吗?我今天在网上寻找解决方案,但似乎没有任何效果。
更新1:我使用此处找到的代码测试了 cv.QueryFrame(capture) 在一个单独的 Stack Overflow 问题 中,它起作用了;所以我几乎将其归结为网络摄像头问题。
更新 2:事实上,我在一台甚至没有网络摄像头的计算机上遇到了完全相同的错误!看起来 TX2500 不兼容...
I wrapped opencv today with simplecv python interface. After going through the official SimpleCV Cookbook I was able to successfully Load, Save, and Manipulate images. Thus, I know the library is being loaded properly.
However, under the Using a Camera, Kinect, or Virtual Camera heading I was unsuccessful in running some commands. In particular, mycam = Camera()
worked, but img = mycam.getImage()
produced the following error:
In [35]: img = mycam.getImage().save()
OpenCV Error: Bad argument (Array should be CvMat or IplImage) in cvGetSize, file /home/jordan/OpenCV-2.2.0/modules/core/src/array.cpp, line 1237
---------------------------------------------------------------------------
error Traceback (most recent call last)
/home/simplecv/<ipython console> in <module>()
/usr/local/lib/python2.7/dist-packages/SimpleCV-1.1-py2.7.egg/SimpleCV/Camera.pyc in getImage(self)
332
333 frame = cv.RetrieveFrame(self.capture)
--> 334 newimg = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
335 cv.Copy(frame, newimg)
336 return Image(newimg, self)
error: Array should be CvMat or IplImage
I'm running Ubuntu Natty on a HP TX2500 tablet. It has a built in webcam, (CyberLink Youcam?) Has anybody seen this error before? I've been all over the web today looking for a solution, but nothing seems to be doing the trick.
Update 1: I tested cv.QueryFrame(capture) using the code found here in a separate Stack Overflow question and it worked; so I've pretty much nailed this down to a webcam issue.
Update 2: In fact, I get the exact same errors on a machine that doesn't even have a webcam! It's looking like the TX2500 is not compatible...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
由于SimpleCV的Camera.py引发了错误,因此您需要调试getImage()方法。如果您可以编辑它:
然后运行您的程序,它将作为 pdb.set_trace() 暂停,在这里您可以检查帧的类型,并尝试找出如何获取帧的大小。
或者您可以在代码中进行捕获,并检查框架对象:
since the error raised from Camera.py of SimpleCV, you need to debug the getImage() method. If you can edit it:
then run your program, it will be paused as pdb.set_trace(), here you can inspect the type of frame, and try to figure out how get the size of frame.
Or you can do the capture in your code, and inspect the frame object:
回答我自己的问题...
我今天买了一台 Logitech C210,问题就消失了。
我现在收到警告:
损坏的 JPEG 数据:标记 0xYY 之前有 X 个无关字节
。但是,我可以通过
JpegStreamer()
成功将视频流推送到我的网络浏览器。如果我无法解决此错误,我将打开一个新线程。因此,现在我将责任归咎于 TX2500。
如果将来有人找到修复方法,请发布。
支持@HYRY 进行调查。谢谢。
To answer my own question...
I bought a Logitech C210 today and the problem disappeared.
I'm now getting warnings:
Corrupt JPEG data: X extraneous bytes before marker 0xYY
.However, I am able to successfully push a video stream to my web-browser via
JpegStreamer()
. If I cannot solve this error, I'll open a new thread.Thus, for now, I'll blame the TX2500.
If anybody finds a fix in the future, please post.
Props to @HYRY for the investigation. Thanks.
我正在使用 OpenCV 获取相机
I'm geting the camera with OpenCV
Anthony,这里的 SimpleCV 开发人员之一。
另外,此函数不是使用 image.save(),而是将文件/视频写入磁盘,您可能想使用 image.show()。如果需要,您可以保存,但是您需要指定一个文件路径,例如 image.save("/tmp/blah.png")
所以您想做:
至于该型号的相机,我不确定它是否有效或不是。我应该注意的是,我们还包装了不同的相机类,而不仅仅是 OpenCV,这是因为 OpenCV 对于超过 640x480 的网络摄像头有问题,我们现在可以做高分辨率相机。
Anthony, one of the SimpleCV developers here.
Also instead of using image.save(), this function writes the file/video to disk, you instead probably want to use image.show(). You can save if you want, but you need to specify a file path like image.save("/tmp/blah.png")
So you want to do:
As for that model of camera I'm not sure if it works or not. I should note that we also wrapper different camera classes not just OpenCV, this is because OpenCV has a problem with webcams over 640x480, we now can do high resolution cameras.
另外我应该提到的是,我没有意识到的是,低于 2.3 的 OpenCV 在 Ubuntu 11.04 及更高版本上的网络摄像头中被破坏了。我没有意识到这一点,因为我之前运行的是 Ubuntu 10.10,从输出的外观来看,你使用的是 python 2.7,这让我认为你使用的是 Ubuntu 11.04 或更高版本。无论如何,我们已经解决了这个问题。现在它被推送到 master 中,它基本上会检查 OpenCV 是否正常工作,如果不正常,它将回退到 pygame。
此修复程序也将出现在 SimpleCV 1.2 版本中(现在位于 master 分支中)
Also I should mention, which I didn't realize, is that OpenCV less than 2.3 is broken with webcams on Ubuntu 11.04 and up. I didn't realize this as I was running Ubuntu 10.10 before, by the looks of your output you are using python 2.7 which makes me think you are on Ubuntu 11.04 or higher. Anyway, we have a fix for this problem. It is now pushed up into the master, it basically does a check to see if OpenCV is working, if not it will fall back to pygame.
This fix will also be in the 1.2 release of SimpleCV (It's in the master branch now)