Ask Your Question

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

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

jla gravatar image

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

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/", 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,



edit retag flag offensive close merge delete



Have you loaded the classifier successfully?

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

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

berak gravatar imageberak ( 2015-01-05 05:17:49 -0500 )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 -0500 )edit

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

berak gravatar imageberak ( 2019-01-20 03:33:29 -0500 )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 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

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

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

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:

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

edit flag offensive delete link more


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 -0500 )edit

The Docu is here:

So just

FooBar gravatar imageFooBar ( 2015-01-05 05:34:15 -0500 )edit

thank you,

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


returns false

jla gravatar imagejla ( 2015-01-05 05:45:30 -0500 )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 -0500 )edit

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


writing the whole path like:


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 -0500 )edit

Question Tools

1 follower


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

Seen: 108,869 times

Last updated: Jan 05 '15