Ask Your Question
4

Why is my haar classifier slow?

asked 2013-06-17 08:47:13 -0600

prerna1 gravatar image

updated 2013-06-18 09:24:06 -0600

I trained a HAAR classifier to detect hands in a LIVE VIDEO FEED from the webcam. I used 621 positives & 3712 negatives.

I used opencv_createsamples to generate the vec file for positives: ./opencv_createsamples -vec /Users/.../positivesvec.vec -info /Users/.../positiveDesc.txt -w 20 -h 30

And then, I used opencv_traincascade to train the classifier: opencv_traincascade -data /Users/.../hand -vec /Users/.../positivesvec.vec -bg /Users/.../negativeDesc.txt -numPos 621 -numNeg 3712 -numStages 15 minHitRate 0.999 maxFalseAlarmRate 0.5 -w 20 -h 30 -mode ALL

The training took around 30 hours or so and I got an xml file. However, when I use that xml file for detection, it is really VERY slow (1 frame in 3-4 seconds maybe).

I know that my object detection code is correct because it works perfectly for faces. This is what I use:

trained_cascade_name = "/Users/.../cascade.xml"; 
if( !cascade.load( trained_cascade_name ) ){ qDebug()<<"Error loading cascade file!"; return; }; 
std::vector<Rect> hands;
Mat frame_gray; // Haar works on grayscale images
cvtColor(frame, frame_gray, CV_RGB2GRAY);
equalizeHist(frame_gray, frame_gray);

cascade.detectMultiScale( frame_gray, hands, 1.1, 3, 0|CV_HAAR_DO_CANNY_PRUNING|CV_HAAR_FIND_BIGGEST_OBJECT, cv::Size(30,30),cv::Size(100,100));
        CvPoint topleft, bottomright;
for( int i = 0; i < hands.size(); i++ )
{
            topleft.x=hands[i].x;
            topleft.y=hands[i].y;
            bottomright.x=hands[i].x+hands[i].width;
            bottomright.y=hands[i].y+hands[i].height;
            cv::rectangle(frame, topleft, bottomright, Scalar(255,0,255), 1, 8, 0);
}

EDIT:

Could it be because of my dataset? http://answers.opencv.org/question/4722/cascadeclassifierdetectmultiscale-takes-a-minute/?comment=15341#comment-15341

edit retag flag offensive close merge delete

Comments

1

Here is a well received answer on the topic http://answers.opencv.org/question/755/object-detection-slow/#760

sammy gravatar imagesammy ( 2013-06-18 06:49:25 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-06-17 09:30:39 -0600

SR gravatar image

Try to decrease the image resolution.

edit flag offensive delete link more

Comments

By image resolution, what are you referring to? Can you be more specific please?

prerna1 gravatar imageprerna1 ( 2013-06-17 12:38:04 -0600 )edit

I know what image resolution is. But are you referring to the image resolution of the positives and negatives or are you referring to the image size specified while creating the vec file?

prerna1 gravatar imageprerna1 ( 2013-06-18 06:34:56 -0600 )edit
1

Sorry, I meant the resolution of those images you apply the detector to. If the image is large, the multi-scale sliding window search is slow because it depends quadratically on the image size (unless you don't change the step size between adjacent windows).

SR gravatar imageSR ( 2013-06-18 07:23:03 -0600 )edit

Question Tools

Stats

Asked: 2013-06-17 08:47:13 -0600

Seen: 1,401 times

Last updated: Jun 18 '13