maxbit89 maxbit89 - 2 months ago 53
Java Question

OpenCV 3.0.0 FaceDetect Sample fails

I am trying to get OpenCV running i am using the following
sample code

I get the following Error line displayed:

OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file ..\..\..\..\opencv\modules\objdetect\src\cascadedetect.cpp, line 1580
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\objdetect\src\cascadedetect.cpp:1580: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale
at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method)
at org.opencv.objdetect.CascadeClassifier.detectMultiScale(
at org.maxbit.opencv.samples.SampleB.main(

Can any body tell me what that error means or how to debug this?


This happens usually for two reasons.

  1. Cascade classifier file lbpcascade_frontalface.xml not present at specified path.
  2. Cascade classifier file is corrupted.

To get an error message instead of exception during runtime, try code sample as below. The CascadeClassifier constructor is silent, if it cannot load the cascade classifier XML. The onus is on the developer to call the empty() method and check if classifier is loaded correctly

CascadeClassifier cascade = new CascadeClassifier( CASCADE_CLASSIFIER_PATH );
if ( cascade.empty() ) {
    //handler error here

Exception you got is from OpenCV native code assertion here.