Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV 2.4 VideoCapture not working on Windows

I'm using Python bindings to OpenCV 2.4 installed with following instructions.

My problem is similar to this one, but I need Windows machine solution.

Problem: when I try to use

cap = cv2.VideoCapture(0) print cap.grab() 

it works fine, but the following code

cap = cv2.VideoCapture(filename) print cap.grab() 

always return False.

Path to the file is correct, absolute and has no spaces.

I tried on two machines with Windows XP and Windows 7 with similar results. On Linux (Ubuntu) it works fine for me.

like image 279
Bihaqo Avatar asked Jul 28 '12 07:07

Bihaqo


2 Answers

Add C:\OpenCV\3rdparty\ffmpeg\ to the Windows PATH environment variable or copy opencv_ffmpeg.dll from that directory to C:\Python27\ or to a directory that is in the PATH. Alternatively, use the OpenCV binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.

Renaming the opencv_ffmpeg.dll file may also be necessary.

For OpenCV version X.Y.Z
opencv_ffmpeg.dll ==> opencv_ffmpegXYZ.dll

For 64-bit OpenCV version X.Y.Z
opencv_ffmpeg.dll ==> opencv_ffmpegXYZ_64.dll

like image 134
cgohlke Avatar answered Sep 20 '22 16:09

cgohlke


Copying opencv_ffmpeg.dll wasn't enough for me - I had to rename it to opencv_ffmpeg246.dll, when I used OpenCV 2.4.6 with Python 2.7.5

like image 23
emem Avatar answered Sep 19 '22 16:09

emem