I'm using this script.py:
import cv2,numpy as np
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default1.xml')
cap = cv2.VideoCapture('video.flv')
ret,frame = cap.read()
print ret
while (cap.isOpened()):
ret,frame = cap.read()
img = frame
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.5, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
cv2.imshow('video',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
I have added ffmpeg to the path with the bat script:
set PATH=%PATH%;C:\opencv\sources\3rdparty\ffmpeg
I have tried to change the file format to .avi, .flv, .mp4 but it still doesn't work.
I don't have any error, but 'ret = False' everytime.
It's hard to tell what exactly is wrong without more informations about error, but you may try following solutions:
brew install opencv --with-ffpmeg
(or similar command - i can't check it right now, but brew options opencv
will give the answer. On Windows probably it's not necessary, but you may try. cv2.pyd
(most likely python_version/Lib/ or python_version/Lib/site-packages). Instruction is here , part "Installation by Making Your Own Libraries from the Source Files". Make sure to check following options: WITH_FFMPEG
( WITH_DSHOW
might be usefull on windows as well) and 'BUILD_opencv_python' and configure python (it's decribed in tutorial - instead of using setuptools
you may prefer to use pip
). After building solution, in opencv_build/lib/[Release/Debug]
you should find cv2.lib
, cv2.pyd
and cv2.ilk
files and in opencv_build/bin/[Release/bin]
should be opencv_...version.dll files (... - module name, version - version number). Copy all those files (from lib/[Debug/Release]' and from
bin/[Debug/Release]`) to folder in which you currently have cv2.pyd.'
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.