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