Error in face detection

while executing the exact same code i am getting a error

this code is


import cv2

cap = cv2.VideoCapture(0)

face_cascade= cv2.CascadeClassifier(“haarcascade_frontalface_alt.xml”)

while True:

ret,frame = cap.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

if ret == False:

    continue

faces = face_cascade.detectMultiScale(frame, 1.3,5)

for (x, y, w, h) in faces:

    cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)

cv2.imshow("Frame", frame) 

key  = cv2.waitKey(1) & 0xFF

if key == ord('q'):

    break

cap.release()

cv2.destroyAllWindows()


the error is —

error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function ‘cv::CascadeClassifier::detectMultiScale’

please help

Hey @yashb4569, make sure haarcascade_frontalface_alt.xml exists in the same folder as is your .py file.
Here is the link of haarcascade file,

Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section. :blush:

still having the same error

Hey @yashb4569, copy the code from github repo and try running it. Make sure your camera light opens atleast once when you run your code.