Video capture issue in python

asked 2012-09-20 11:41:42 -0500

blimp555 gravatar image

updated 2012-09-25 10:41:57 -0500

Kirill Kornyakov gravatar image

I am having trouble with the following simple code snippet:

import as cv
capture = cv.CaptureFromFile('C://video.mp4') 
frame = cv.QueryFrame(capture)
frame_size = cv.GetSize(frame)

cv.GetSize gives this error:

error: Array should be CvMat or IplImage

frame is of type <type 'nonetype'="">, so QueryFrame is not returning properly. capture seems to be ok. It is type <type 'cv2.capture'=""> and has a valid looking value: <capture 03673420="">.

Here are the details of my setup: Python 2.7.3, OpenCV 2.4.2, OS = Windows 7.

I can view the video.mp4 file in windows media player. I can open jpg files successfully with:

frame = cv.LoadImageM('C://test.jpg',cv.CV_LOAD_IMAGE_COLOR);

Whatever I do, I haven't been able to open video files with OpenCV. Any suggestions?

edit retag flag offensive close merge delete



In the meantime you can try cv2 API:

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-09-25 10:42:57 -0500 )edit

I just tried and am not having any luck. I've tried this on two Windows7 64 bit machines, and I get the same error on both: cv2.imshow('some', img) error: ......\src\opencv\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or unsupported array type

I installed Python 2.7.2 and opencv 2.4.2 on both machines. Is there something I'm doing wrong with the installation? Should I try a different version of opencv? Any suggestions would be helpful. Thanks!

blimp555 gravatar imageblimp555 ( 2012-09-25 13:59:06 -0500 )edit

Sorry, but I don't work with Python usually, that's why I can't try your code. But could you also check this sample or other python samples. You can grep for cv2.VideoCapture and try all of them...

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-09-26 01:32:04 -0500 )edit