开发者

opencv getImage() error

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...


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)


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.


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


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜