opencv getImage() 错误

发布于 2024-11-28 08:05:30 字数 1841 浏览 0 评论 0原文

今天我用 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。它有一个内置网络摄像头(Cyber​​Link 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

我的鱼塘能养鲲 2024-12-05 08:05:30

由于SimpleCV的Camera.py引发了错误,因此您需要调试getImage()方法。如果您可以编辑它:

def getImage(self):
    if (not self.threaded):
        cv.GrabFrame(self.capture)

    frame = cv.RetrieveFrame(self.capture)
    import pdb       # <-- add this line
    pdb.set_trace()  # <-- add this line
    newimg = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
    cv.Copy(frame, newimg)
    return Image(newimg, self)

然后运行您的程序,它将作为 pdb.set_trace() 暂停,在这里您可以检查帧的类型,并尝试找出如何获取帧的大小。

或者您可以在代码中进行捕获,并检查框架对象:

mycam = Camera()
cv.GrabFrame(mycam.capture)
frame = cv.RetrieveFrame(mycam.capture)

since the error raised from Camera.py of SimpleCV, you need to debug the getImage() method. If you can edit it:

def getImage(self):
    if (not self.threaded):
        cv.GrabFrame(self.capture)

    frame = cv.RetrieveFrame(self.capture)
    import pdb       # <-- add this line
    pdb.set_trace()  # <-- add this line
    newimg = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
    cv.Copy(frame, newimg)
    return Image(newimg, self)

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:

mycam = Camera()
cv.GrabFrame(mycam.capture)
frame = cv.RetrieveFrame(mycam.capture)
多孤肩上扛 2024-12-05 08:05:30

回答我自己的问题...

我今天买了一台 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.

眼眸里的快感 2024-12-05 08:05:30

我正在使用 OpenCV 获取相机

from opencv import cv
from opencv import highgui
from opencv import adaptors

def get_image()
    cam = highgui.cvCreateCameraCapture(0)
    im = highgui.cvQueryFrame(cam)
    # Add the line below if you need it (Ubuntu 8.04+)
    #im = opencv.cvGetMat(im)
    return im

I'm geting the camera with OpenCV

from opencv import cv
from opencv import highgui
from opencv import adaptors

def get_image()
    cam = highgui.cvCreateCameraCapture(0)
    im = highgui.cvQueryFrame(cam)
    # Add the line below if you need it (Ubuntu 8.04+)
    #im = opencv.cvGetMat(im)
    return im
旧时光的容颜 2024-12-05 08:05:30

Anthony,这里的 SimpleCV 开发人员之一。

另外,此函数不是使用 image.save(),而是将文件/视频写入磁盘,您可能想使用 image.show()。如果需要,您可以保存,但是您需要指定一个文件路径,例如 image.save("/tmp/blah.png")

所以您想做:

img = mycam.getImage()
img.show()

至于该型号的相机,我不确定它是否有效或不是。我应该注意的是,我们还包装了不同的相机类,而不仅仅是 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:

img = mycam.getImage()
img.show()

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.

物价感观 2024-12-05 08:05:30

另外我应该提到的是,我没有意识到的是,低于 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文