Ask Your Question

LatentSVM crashes in OpenCV 3.0.0 (contrib)

asked 2015-02-09 09:51:23 -0600

verified.human gravatar image

I am trying to detect objects using the LatentSVM detector that is currently in the contrib repository for OpenCV. My OpenCV installation is 3.0.0 on OS X Mavericks. After loading the model successfully from the opencv_extra repository the detector crashes upon finding objects in an image. In this example I have loaded the car.xml model but this does not seem to be the problem.

void LSVM_Detector::detect(cv::Mat& image)
    if (detector->isEmpty()) {
        cout << "Model is not loaded...EXIT" << endl;

    // Line below outputs '1'
    //cout << "Number of classes = " << detector->getClassCount() << endl;

    // Actual detection of objects in the image
    cout << "Detecting objects..." << flush;
    vector<LSVMDetector::ObjectDetection> detections;

    // Line below crashes...
    detector->detect(image, detections);
    cout << "DONE" << endl;
    cout << "Found " << detections.size() << " objects." << endl;

    cv::namedWindow("LSVM Detections", cv::WINDOW_AUTOSIZE);

    for (auto&d  : detections) {
        cv::Rect r  = d.rect;
        float score = d.score;

        cout << "Detection score = " << score << endl;
        cv::rectangle(image, r, cv::Scalar(0, 255, 0));

    cv::imshow("LSVM Detections", image);

I have tried to read out images in color and grayscale, however both result in the same error:

init done 
opengl support available 
Loading LSVM model file...DONE
Detecting objects...OpenCV Error: Assertion failed (src.size == dst.size && src.channels() == dst.channels()) in cvConvertScale, file /Users/username/Development/libraries/opencv-3.0.0-beta/modules/core/src/convert.cpp, line 4008
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/username/Development/libraries/opencv-3.0.0-beta/modules/core/src/convert.cpp:4008: error: (-215) src.size == dst.size && src.channels() == dst.channels() in function cvConvertScale

I have tried various images, but unfortunately without any luck. Does anyone have an idea what goes wrong here? Any help would be appreciated, I am kind of stuck and the documentation of OpenCV (3.0.0) and the LatentSVM class lacks a little bit here to be honest. Thanks in advance!

edit retag flag offensive close merge delete


give it 24bit bgr images, not grayscale ;)

berak gravatar imageberak ( 2015-02-09 10:12:56 -0600 )edit

Berak, thanks for your reply! When giving it a 24 bit BGR image the error changes, but now I get a EXC_BAD_EXCESS error. I am not sure whether this is an OpenCV issue or has something to do with OS X or Xcode...?

This screenshot shows the error message, there is nothing to debug...It just crashes :-( Any clue?

verified.human gravatar imageverified.human ( 2015-02-09 14:13:02 -0600 )edit

are you sure, you got the correct cascade ? must be one from opencv_contrib\modules\latentsvm\testdata\latentsvm, the old ones from opencv_extra do no more work (crash in detect / createPCA_FeaturePyramid)

berak gravatar imageberak ( 2015-02-09 15:25:22 -0600 )edit

yes, the algorithm behind it was changed slightly, afaik, it's using a 'star' based cascade now, so the old cascade files do no more work.

berak gravatar imageberak ( 2015-02-10 03:35:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-02-10 03:26:37 -0600

verified.human gravatar image

Thanks you are right! I was using the model files as suggested here (opencv_extra repository):

But I guess that was changed in OpenCV 3.0.0 - Many thanks for your help!!

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-02-09 09:51:23 -0600

Seen: 627 times

Last updated: Feb 09 '15