Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV 3.0.0 FaceDetect Sample fails

Tags:

java

opencv

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(CascadeClassifier.java:176)
    at org.maxbit.opencv.samples.DetectFaceDemo.run(SampleB.java:29)
    at org.maxbit.opencv.samples.SampleB.main(SampleB.java:51)

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

like image 506
maxbit89 Avatar asked Dec 07 '14 16:12

maxbit89


Video Answer


2 Answers

I also faced the problem. The problem is in the .getPath() return an absolute path of the format.

Eg: "/C:/Users/projects/FaceDetection/bin/com/face/detection/haarcascade_frontalface_alt.xml".

So change the code like this.

CascadeClassifier faceDecetor = new CascadeClassifier(FaceDetection.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
like image 144
Aung Myat Hein Avatar answered Oct 15 '22 03:10

Aung Myat Hein


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.

like image 20
kiranpradeep Avatar answered Oct 15 '22 03:10

kiranpradeep