我的代码是检测视频中的脸部,但即使我已经给出了正确的路径,视频也没有被加载。另外,我安装了ffmpeg,但其中没有.dll文件。
有人可以帮忙吗?
import cv2
import numpy as np
faceDetect=cv2.CascadeClassifier('C:\\OPENCV\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml')
ret,cam=cv2.VideoCapture('D:\\New folder (5)\\New folder (3)\\Ae Dil Hai Mushkil.mp4')
img=cam.read()
while(cam.isOpened()):
ret,img=cam.read();
if not ret: break
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=faceDetect.detectMultiScale(gray,1.3,5);
`enter code here`for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
cv2.imshow("Face",img);
if(cv2.waitKey(1) & 0xFF==ord('q')):
break;
cam.release()
cv2.destroyAllWindows()
错误:
Traceback (most recent call last):
File "D:\New folder (5)\New folder (3)\facedet.py", line 5, in <module>
ret,cam=cv2.VideoCapture('D:\\New folder (5)\\New folder (3)\\Ae Dil Hai Mushkil.mp4')
TypeError: 'cv2.VideoCapture' object is not iterable
答案 0 :(得分:0)
尝试更改:
ret,cam=cv2.VideoCapture('D:\\New folder (5)\\New folder (3)\\Ae Dil Hai Mushkil.mp4')
img=cam.read()
要:
cam=cv2.VideoCapture('D:\\New folder (5)\\New folder (3)\\Ae Dil Hai Mushkil.mp4')
ret,img=cam.read()