I have the following working code in python using opencv (it is tested on another environment), but for some reason I tried to play the video on my computer with Windows 10, Python27 and OpenCV 3.0.0. And it does not play.
Question: what can I do to play video in opencv under python 2.7? and what I am doing wrong?
Here is my code:
import cv2
cap = cv2.VideoCapture("output.avi")
cv2.namedWindow("input")
f = True
while (f):
f, img = cap.read()
if f == True:
cv2.imshow("input", img)
ch = cv2.waitKey(33)
if ch == 32:
break
cap.release()
cv2.destroyAllWindows()
I have had the similar issue, and I have fixed the following way:
In order to get your Python 2.7 to play videos using OpenCV library, you need to have the proper OpenCV codex.
To confirm if it is an OpenCV codex issue, first you need to copy opencv_world300.lib
TEMPORARY from you OpenCV library to your Python folder. In my case OpenCV installed under (you should check where your OpenCV installed)
C:\lib\opencv\build\x86\vc12\lib
As mentioned copy it to your Python folder, like again in my case c:\python27
(find out where your Python folder is located).
Than start to compile your code and see if you can play your video.
If that helps and succeeded, this means your path and environment variables is not correctly set. Therefore, you need to set the following path and environment variables:
Go in your windows System -> Advance system settings -> Environment Variables
(if you don't know how look at this)
And add following in User variables, this is how my variables are setup.
Edit your variable name path and add new variable values:
%OPENCV_HOME%\x86\vc12\bin
%PYTHON_HOME%
%PYTHON_HOME%\Scripts
%PYTHON_HOME%\DLLs
So it will look like this in Windows
%OPENCV_HOME%\x86\vc12\bin;%PYTHON_HOME%;%PYTHON_HOME%\Scripts;%PYTHON_HOME%\DLLs;....etc.
Create new variable name and variable value for following three components:
PYTHON_HOME=C:\Python27\
OPENCV_HOME=C:\lib\opencv\build
NUMPY_HOME=%PYTHON_HOME%\Lib\site-packages\numpy
So it will look like this in Windows for Python as example and the rest is the same way:
Remember! to restart your console or your IDE so it get updated/fresh variables.
Note:
opencv_world300.lib
and remember to delete it from Python folder as we move it only to clarify if that was the issue.Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments