I'm using haarcascade_fontalface_default.xml file to face detection. This is my code
import cv2
#load some free trained data on face fontals from opencv(haarcascade)
trained_face_data=cv2.CascadeClassifier('haarcascade_fontalface_default.xml')
#choose an image to detect faces in
img = cv2.imread('ahk.jpg')
#covert color
#ashshak = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#Detect faces
face_coordinates = trained_face_data.detectMultiScale(img)
print(face_coordinates)
#name of the window where the image will show
cv2.imshow('Face detector opencv',img)
#To set the delay time
cv2.waitKey()
print("code completed")
but when I try to run the code, I have been facing this error all the time. Can any body please help me to find out the solution
this my error:
Traceback (most recent call last):
File "E:/python/opencv/Facedetection.py", line 13, in <module>
face_coordinates = trained_face_data.detectMultiScale(img)
cv2.error: OpenCV(4.3.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'