I would like to use HAAR to detect faces.
I first ran the following code:
#use HAAR cascade to detect faces
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
# Detect faces
faces = face_cascade.detectMultiScale(img)
When doing so, I get the following error:
error: OpenCV(4.1.0) /home/vocuser/tmp/xeus/4.1.opencv/opencv/modules/objdetect/src/cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'
I read that I am getting the error because the XML file could not be found. So I did the following:
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
# Detect faces
faces = face_cascade.detectMultiScale(img)
But now I'm getting the following error:
AttributeError: module 'cv2' has no attribute 'data'
So what is the correct approach? How can I use the detectMultiScale
function?