First time here? Check out the FAQ!

Ask Your Question
0

full body detection with c+

asked Oct 3 '13

rokasma gravatar image

updated Oct 3 '13

Hi, I am new with OpenCV. I wrote a code for human full body detection, but it works not very well. Sometimes when I stay infront of camera, it does not recognise me. Maybe I done some mistakes in my code. I hope You understand me.

#include "opencv2/objdetect/objdetect.hpp" 
#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp"

#include <iostream> 
#include <stdio.h>

using namespace std; 
using namespace cv;

/** Function Headers */ 

void detectAndDisplay( Mat frame );

/** Global variables */ 
String body_cascade_name = "haarcascade_fullbody.xml";
CascadeClassifier body_cascade; 
string window_name = "Capture - Face detection"; 
RNG rng(12345);

/** @function main */
int main( int argc, const char** argv ) 
{ 
CvCapture* capture;
Mat frame;

//-- 1. Load the cascades 

if( !body_cascade.load( body_cascade_name ) )
{ 
    printf("--(!)Error loading\n"); return -1; 
};

//-- 2. Read the video stream 
capture = cvCaptureFromCAM( -1 ); 
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 180 );
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 180 );

if( capture ) 
{ 
    while( true ) 
    { 
        frame = cvQueryFrame( capture );

        //-- 3. Apply the classifier to the frame 
        if( !frame.empty() ) 
        { 
            detectAndDisplay( frame ); 
        } else { 
            printf(" --(!) No captured frame -- Break!"); 
            break; 
        }
        int c = waitKey(100); 
        if( (char)c == 'c' ) 
        { 
            break; 
        } 
    } 
} 
return 0; 
}

/** @function detectAndDisplay */ 
void detectAndDisplay( Mat frame ) 
{ 
    vector<Rect> bodys;
    Mat frame_gray;

    cvtColor( frame, frame_gray, CV_BGR2GRAY ); 
    equalizeHist( frame_gray, frame_gray );
    //-- detect body */
    body_cascade.detectMultiScale(frame_gray, bodys, 1.1, 2, 18|9, Size(3,7));
    for( int j = 0; j < bodys.size(); j++ ) 
        { 
            Point center( bodys[j].x + bodys[j].width*0.5, bodys[j].y+ + bodys[j].height*0.5 ); 
            ellipse( frame, center, Size( bodys[j].width*0.5, bodys[j].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );
        } 
    imshow( window_name, frame ); 
}
Preview: (hide)

Comments

Unfortunatelly haar classifier is far from ideal. Try to combine object tracking algorithms, like camshift with haar recognition, use haar to capture object and then track it with other algorithm.

What do you want to achieve btw?

Maxim Galushka gravatar imageMaxim Galushka (Oct 4 '13)edit

I want to recognize and detect people from video stream

rokasma gravatar imagerokasma (Oct 6 '13)edit

2 answers

Sort by » oldest newest most voted
0

answered Nov 15 '13

have error line

for( int j = 0; j < bodys.size(); j++ ) { Point center( bodys[j].x + bodys[j].width0.5, bodys[j].y+ + bodys[j].height0.5 ); ellipse( frame, center, Size( bodys[j].width0.5, bodys[j].height0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 ); }

Preview: (hide)
0

answered Oct 4 '13

I'm not sure Haar Cascade is very accurate. You can also try HOG person detector: http://docs.opencv.org/modules/gpu/doc/object_detection.html

or latent svm with the "person" model: http://docs.opencv.org/modules/objdetect/doc/latent_svm.html

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Oct 3 '13

Seen: 13,824 times

Last updated: Nov 15 '13