Ask Your Question
0

OpenCV Error: Assertion failed (!empty()) in detectMultiScale

asked 2015-01-05 05:06:48 -0600

jla gravatar image

updated 2019-02-12 14:54:01 -0600

LBerger gravatar image

Hi, i am trying to work with the example from the face-detection tutorial: tutorial link

While i do so and try to execute the examplecode in python, the following error occurs:

OpenCV Error: Assertion failed (!empty()) in detectMultiScale, file /home/julian/Downloads/opencv-3.0.0-beta/modules/objdetect/src/cascadedetect.cpp, line 1580 Traceback (most recent call last): File "/home/julian/PycharmProjects/PicProcessingTutorial/Face_Detection.py", line 15, in <module> faces = face_cascade.detectMultiScale(gray, 1.3, 5) cv2.error: /home/julian/Downloads/opencv-3.0.0-beta/modules/objdetect/src/cascadedetect.cpp:1580: error: (-215) !empty() in function detectMultiScale

What could be the reason for the error, how should i react to fix it? Thank you for your time and advice,

regards

jla

edit retag flag offensive close merge delete

Comments

2

Have you loaded the classifier successfully?

FooBar gravatar imageFooBar ( 2015-01-05 05:13:52 -0600 )edit
1

your cascade-file was not loaded (probably not found).

berak gravatar imageberak ( 2015-01-05 05:17:49 -0600 )edit

I'm having the same error. face_cascade.load returns false. what am i supposed to do?

bns gravatar imagebns ( 2019-01-20 03:28:42 -0600 )edit

@bns, try an absolute path to the resp. xml file

berak gravatar imageberak ( 2019-01-20 03:33:29 -0600 )edit

I think either the name of file is wrong or file is not present in working directory

Shivanand Pandey gravatar imageShivanand Pandey ( 2020-03-28 13:47:24 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-01-05 05:18:22 -0600

updated 2015-01-05 05:21:18 -0600

This looks as if you don't load the classifier successfully from the file. Could you read it via CascadeClassifier::load(filename) and check that it returns true?

This is the code for the classifier: https://github.com/Itseez/opencv/blob...

The bool CascadeClassifier::empty() is in line 1553 and ::load is just below.

edit flag offensive delete link more

Comments

thanks for your fast answer. Since i'm using opencv as a wrapper and the programm is in python, i need a little heads up, how to call the CascadeClassifier::load() from pythoncode!? Thanks in advance

jla gravatar imagejla ( 2015-01-05 05:28:55 -0600 )edit

The Docu is here: http://docs.opencv.org/modules/objdet...

So just

face_cascade.load('haarcascade_frontalface_default.xml')
FooBar gravatar imageFooBar ( 2015-01-05 05:34:15 -0600 )edit

thank you,

test = face_cascade.load('haarcascade_frontalface_default.xml')

print(test)

returns false

jla gravatar imagejla ( 2015-01-05 05:45:30 -0600 )edit

ok. If this solved your problem, it would be nice if you accept my answer as correct.

FooBar gravatar imageFooBar ( 2015-01-05 05:50:36 -0600 )edit
1

Well, the solution is (for any readers experiencing the same problem): instead of

face_cascade.load('haarcascade_frontalface_default.xml')

writing the whole path like:

face_cascade.load('/home/user/.../haarcascade_frontalface_default.xml')

should do it, and you Sir FooBar helped ,me a lot. Thank you very much, here ist your correct answer :) Have a nice day!

jla gravatar imagejla ( 2015-01-05 05:59:29 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-01-05 05:06:48 -0600

Seen: 127,545 times

Last updated: Jan 05 '15