haarcascades error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
ZaccD0099 opened this issue · comments
Continue getting this error for drone face tracking course, I think it is due to the file. Any ideas?
My Code:
import cv2
import numpy as np
def findFace(img):
faceCascade = cv2.CascadeClassifier('Resources/haarcascade_frontalface_default.xml')
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(imgGray,1.1,8)
myFaceListC = []
myFaceListArea = []
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x + w, y + h),(0,0,255),2)
cap = cv2.VideoCapture(0)
while True:
_, img = cap.read()
findFace(img)
cv2.imshow("Output",img)
cv2.waitKey(1)
Error:
File "C:/Users/zachd/PycharmProjects/droneproject2/venv/Face Tracking.py", line 20, in
findFace(img)
File "C:/Users/zachd/PycharmProjects/droneproject2/venv/Face Tracking.py", line 7, in findFace
faces = faceCascade.detectMultiScale(imgGray,1.1,8)
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-oduouqig\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
[ WARN:1] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-oduouqig\opencv\modules\videoio\src\cap_msmf.cpp (434) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback