Ask Your Question
0

full body detection with c+

asked 2013-10-03 08:44:28 -0600

rokasma gravatar image

updated 2013-10-03 08:46:51 -0600

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 ); 
}
edit retag flag offensive close merge delete

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 ( 2013-10-04 12:00:03 -0600 )edit

I want to recognize and detect people from video stream

rokasma gravatar imagerokasma ( 2013-10-06 08:20:50 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-11-15 03:09:12 -0600

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 ); }

edit flag offensive delete link more
0

answered 2013-10-04 12:37:20 -0600

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

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-10-03 08:44:28 -0600

Seen: 13,781 times

Last updated: Nov 15 '13