Sunday 14 July 2019

openCV Troubleshooting (0): error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

Trying to compile some example code (in Python) from the internet and got the following error:

Traceback (most recent call last):
  File "main.py", line 16, in <module>
    img = drawFaces(img)
  File "/home/boris/facedetect_example/example2/OpenCV-demo-master/Video-FaceDetection/face_detection.py", line 26, in drawFaces
    faces = detectFaces(img)
  File "/home/boris/facedetect_example/example2/OpenCV-demo-master/Video-FaceDetection/face_detection.py", line 18, in detectFaces
    faces = face_cascade.detectMultiScale(gray, 1.2, 5)
cv2.error: OpenCV(4.1.0) /home/boris/workspace/opencv-4.1.0/modules/objdetect/src/cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

It turns out the cascade XML or file is missing or the path to it is incorrect or the create_capture path is incorrect. Of course, this is someone else's code.

Updated this line:
face_cascade = cv2.CascadeClassifier("/home/aaaaa/OpenCV-demo/opencv-data/haarcascades/haarcascade_frontalface_default.xml")

To 
face_cascade = cv2.CascadeClassifier("/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml")

Everything works now.


ref:
https://stackoverflow.com/questions/30508922/error-215-empty-in-function-detectmultiscale