Search code examples
pythonopencvcompiler-errors

How to solve. error: (-215) !empty() in function detectMultiScale


Hello I have "error: (-215) !empty() in function detectMultiScale"

xml = './haarcascade_hand.xml'
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + xml)

This Code not working...

But another file is work

EX)

xml = './haarcascade_frontalface_alt.xml'
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + xml)

Why do this?

I saw in another question that "error: (-215) !empty() in function detectMultiScale" can be solved by modifying the file path.

But i have the files all in the same place.


Solution

  • That's because there is no such file in cv2.data.haarcascades as it can be seen here.

    You should download the "haarcascade_hand.xml" from this project or any other repo that you have in mind, then provide the full path for this to work.

    it should look like this

    cascade_path = "fullpath_to_hand_cascade/haarcascade_hand.xml"
    hand_cascade = cv2.CascadeClassifier(cascade_path)