0

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'
  • It is probably saying that the image is not read. Try printing the image for this line to confirm this. – Rahul Kedia Jul 27 '20 at 16:07
  • Does this answer your question? [error: (-215) !empty() in function detectMultiScale](https://stackoverflow.com/questions/30508922/error-215-empty-in-function-detectmultiscale) – Martin Brisiak Jul 27 '20 at 19:46

0 Answers0