简体   繁体   中英

OpenCV Python unable to open videofile

I am using Windows 10 and the 2.7.12 32-bit version of Python and Opencv 3.1.0. Below is the code where it goes wrong:

vcap = cv2.VideoCapture("StraightAhead.avi")
if not vcap.isOpened():
    print "File Cannot be Opened"

First off, all of this code works when using webcam (so VideoCapture(0) ).

I have tried a couple of things. First off, it was originally an mp4 so I converted it to avi. I tried a file (.webm) from a friend who is using Linux with python and opencv which worked for him but not for me.

I checked to see if I could move the DLL files from opencv ffmpeg to Python but there are no DLL files for me there. I checked a lot of other questions but most of them give solutions for Linux.

The most relevant question doesn't have any answers or comments so I finally decided to ask it here. I hope someone can help.

Tried your code and it works on my 64-bit Win10 machine. The file you need for 32-bit Windows is 'opencv_ffmpeg310.dll'. Suggest you download the binary from OpenCV Download site , install it and try again. The ffmpeg DLL is located in 'C:\\Program Files (x86)\\OpenCV 3.1.0\\x64\\vc14\\bin'. Also need to add the paths below if the installer doesn't add them to the windows environment.

OPENCV_DIR='C:\Program Files (x86)\OpenCV 3.1.0\x64\vc14' 
PATH = %PATH%;%OPENCV_DIR%\bin

Note that vc14 is compiled by Visual Studio 2015 or vc12 by VS2013.

Hope this help.

You may extact the binary to C:\\ and try again.

  1. Set OPENCV_DIR = C:\\opencv\\build\\x64\\vc14 { opencv_ffmpeg310_64.dll are there }
  2. Add PATH with %OPENCV_DIR%\\bin
  3. Copy C:\\opencv\\build\\python\\2.7\\x86\\cv2.pyd to %PYTHON%\\lib\\site-packages\\cv2.pyd { where %PYTHON% is the 32-bit python root directory, eg "C:\\Program File (x86)\\Python27" }

If still doesn't work, change OpenCV path to use 32-bit version of ffmpeg DLL deliberately.

  1. Set OPENCV_DIR to C:\\opencv\\build\\ { to use 32-bit ffmpeg under bin\\ }

If problem still exists, log the Traceback message.

EDIT: Just tested the opencv-3.1.0.exe downloaded from opencv website. Video file playback, used 'Wildlife.wmv' comes with 32-bit Win7, works.

It looks that the EXE zipped with two set of files ... The OPENCV_DIR was set to C:\\opencv\\opencv\\build\\x86\\vc12. And copied c:\\opencv\\opencv\\build\\python\\2.7\\x86\\cv2.pyd cv2.pyd to python's lib\\site-packages. That's all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM