Opencv getImage () error

I wrapped opencv today using the simplecv python interface. After going through the official SimpleCV Cookbook, I was able to successfully Download, Save, and Manipulate images. This way, I know that the library is loading properly.

However, in the Using Camera, Kinect, or Virtual Camera section of the heading, I was not successful in executing some of the 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 am running Ubuntu Natty on an HP TX2500 tablet. Does it have a built-in webcam (CyberLink Youcam?) Has anyone seen this error before? Today I was on the Internet looking for a solution, but it does nothing of the kind.

Update 1 . I tested cv.QueryFrame (capture) with the code found here in a separate stack overflow question , and it worked; so I pretty nailed it to the webcam problem.

Update 2 . In fact, I get exactly the same errors on a machine that doesn't even have a webcam! It looks like the TX2500 is not compatible ...

+4
source share
5 answers

To answer my own question ...

I bought Logitech C210 today, and the problem disappeared. Now I get warnings:

Corrupt JPEG data: X extraneous bytes before marker 0xYY .

However, I can successfully push the video stream into my web browser through JpegStreamer() . If I cannot solve this error, I will open a new thread.

So for now, I will blame the TX2500. If anyone finds a fix in the future, send a message.

Confirms @HYRY for investigation. Thanks.

0
source

since the error is coming from Camera.py 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 suspended as pdb.set_trace (), here you can check the frame type and try to figure out how to get the frame size.

Or you can capture in your code and check the frame object:

 mycam = Camera() cv.GrabFrame(mycam.capture) frame = cv.RetrieveFrame(mycam.capture) 
+1
source

I get a 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 
0
source

Anthony, one of the developers of SimpleCV.

Also, instead of using the image.save () function, this function writes the file / video to disk; instead, you probably want to use image.show (). You can save if you want, but you need to specify a path to a file such as image.save ("/tmp/blah.png")

So you want:

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

As for this camera model, I'm not sure if it works or not. I should note that we also wrap different classes of cameras not only in OpenCV, this is because OpenCV has problems with webcams over 640x480, now we can make high-resolution cameras.

0
source

Also, I should mention that I did not understand that OpenCV less than 2.3 is broken by webcams on Ubuntu 11.04 and higher. I did not understand this, since I was running Ubuntu 10.10 before, in appearance of your output you are using python 2.7, which makes me think that you are on Ubuntu 11.04 or higher. Anyway, we have a problem with this problem. Now that he has moved to the wizard, he basically checks to see if OpenCV works if he doesn’t return to pygame.

This fix will also be available in version 1.2 of SimpleCV (now in the main branch)

0
source

All Articles