I've been having issues getting OpenCV 2.4.9 to read (and show) a video file using python. I know it's not a problem with finding the file because I was able to get cv2.imread()
to read an image from the same directory. It's definitely a problem with cv2.VideoCapture()
. Here's the code and output I've been getting:
import cv2
import numpy as np
testvid = cv2.VideoCapture('testvid.avi')
while(1):
ret, frame = testvid.read()
print ret
cv2.imshow('frame',frame)
k = cv2.waitKey(30) & 0xff
if k == 27:
break
testvid.release()
cv2.destroyAllWindows()
Output:
False
error: C:\pisi\tmp\opencv-2.4.9-5\work\opencv-2.4.9\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow
OpenCV Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file C:\pisi\tmp\opencv-2.4.9-5\work\opencv-2.4.9\modules\highgui\src\window.cpp, line 261
I know there's been several people who have had the same problem. This thread and this tread both address the issue by saying that you have to rename the opencv_ffmpeg.dll file to fit your version and copy it to the main python directory or directory in your path (or something to that effect).
However, I'm using Python 2.7.13 through Enthought (by recommendation from my professor), and the paths and way libraries and packages are set up seem completely different from how they are in the other threads. Enthought uses a package manager that automatically downloaded and setup OpenCV for me. There is no Python directory. Everything is through Enthought. After some digging, I found where all of the OpenCV .dlls are located, including opencv_ffmpeg249_64.dll:
C:\Users\USERNAME\AppData\Local\Enthought\Canopy\edm\pkgs\03\9d58e152b8f411718220c30639b8448585cb7d9a82de662c7e34b35d9ec1f6
So what do I do with this? Where do I copy the .dll? Is the .dll even the problem here? I've tried so many things, including copying it to all sorts of places and renaming the .dll, and nothing has worked. Help!