0
我的代碼是檢測視頻中的臉部,但即使我給出正確的路徑,視頻也沒有被加載。另外,我安裝了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
請修復縮進。 –