my trained cascade.xml makes the call detectMultiScale(...) hangs [closed]

asked 2017-06-22 02:48:58 -0600

wureka gravatar image

Hi, My environment:

  • Ubuntu Linux 17.04 Desktop 64bit
  • OpenCV 3.2.0

I have two cascades.

One is downloaded from internet -->cars3.xml

The other is trained by myself -->my trained cascade.xml

The tested picture is here currentFrame02.jpg

My opencv_traincascade command is as below:

opencv_traincascade -data classifier -vec data/positive_images/positives.vec -bg data/negative_images/negatives.txt -numStages 20 -w 100 -h 100 -mode BASIC -numPos 182 -numNeg 166 -featureType LBP

My code is as below:

#include <stdio.h>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;
int main() {
    Mat image;
    image = imread("/home/user/opencv_workspace/test_images/currentFrame02.jpg", CV_LOAD_IMAGE_COLOR);
    namedWindow("window1", 1);
    imshow("window1", image);
    waitKey(0);
    CascadeClassifier vehicle_cascade;
    //vehicle_cascade.load("/home/user/opencv_workspace/classifier/cars3.xml");
    vehicle_cascade.load("/home/user/opencv_workspace/classifier/cascade.xml");
    std::vector<Rect> vehicles;
    vehicle_cascade.detectMultiScale(image, vehicles); // hangs here when using cascade.xml
    cout << "find " << vehicles.size() << " vehicles"<< endl;
    for(int i = 0; i < vehicles.size(); i++) {
        Point center(vehicles[i].x + vehicles[i].width*0.5, vehicles[i].y + vehicles[i].height * 0.5);
        ellipse(image, center, Size(vehicles[i].width*0.5, vehicles[i].height* 0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
    }
    imshow("Detected Vehicle", image);
    waitKey(0);
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

If I use the downloaded cars3.xml, the code can detect something and display the result.

However, if I use my trained cascade.xml, the code freezes at line

vehicle_cascade.detectMultiScale(image, vehicles);

Does anybody help me to solve the problem ? Many thanks

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-08 10:05:51.590415