Cheetos
Member level 3
Greetings, i am having problems with openCV face, upper body and lower body detection. in my code, i can only see the face detection, the rest it does not appear. what is wrong with my code?
This is my code:
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
CvHaarClassifierCascade *cascade;
CvMemStorage *storage;
CvHaarClassifierCascade *upperbodyCascade;
CvMemStorage *upperbodyStorage;
CvHaarClassifierCascade *lowerbodyCascade;
CvMemStorage *lowerbodyStorage;
void detectFaces( IplImage *img );
void detectupperbody( IplImage *img );
void detectlowerbody( IplImage *img );
IplImage *bframe = 0;
IplImage *resframe=0;
int main( int argc, char** argv )
{
CvCapture *capture;
IplImage *frame;
int key;
char *filename = "haarcascade_frontalface_alt.xml";
char *upperbodyFilename ="haarcascade_fullbody.xml";
char *lowerbodyFilename ="haarcascade_lowerbody.xml";
/* load the classifier
note that I put the file in the same directory with
this code */
cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );
upperbodyCascade = ( CvHaarClassifierCascade* )cvLoad( upperbodyFilename, 0, 0, 0 );
lowerbodyCascade = ( CvHaarClassifierCascade* )cvLoad( lowerbodyFilename, 0, 0, 0 );
/* setup memory buffer; needed by the face detector */
storage = cvCreateMemStorage( 0 );
upperbodyStorage = cvCreateMemStorage( 0 );
lowerbodyStorage = cvCreateMemStorage( 0 );
/* initialize camera */
capture = cvCaptureFromCAM( 0 );
/* always check */
assert( cascade && storage && capture );
assert( upperbodyCascade && upperbodyStorage && capture );
assert( lowerbodyCascade && lowerbodyStorage && capture );
/* create a window */
cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "upperbody", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "lowerbody",CV_WINDOW_AUTOSIZE );
while( key != 'q' ) {
/* get a frame */
frame = cvQueryFrame( capture );
/* always check */
if( !frame ) break;
/* 'fix' frame */
cvFlip( frame, frame, 1 );
frame->origin = 0;
/* detect faces and display video */
detectFaces(frame);
detectupperbody(frame);// FUNCTION IRE
detectlowerbody(frame); // FUNCTION IRE
/* quit if user press 'q' */
key = cvWaitKey( 10 );
}
/* free memory */
cvReleaseCapture( &capture );
cvDestroyWindow( "video" );
cvDestroyWindow( "upperbody" );
cvDestroyWindow( "lowerbody" );
cvReleaseHaarClassifierCascade( &cascade );
cvReleaseMemStorage( &storage );
return 0;
}
void detectFaces( IplImage *img )
{
int i;
/* detect faces */
CvSeq *faces = cvHaarDetectObjects(
img,
cascade,
storage,
1.1,
3,
0 /*CV_HAAR_DO_CANNY_PRUNNING*/,
cvSize( 40, 40 ) );
/* for each face found, draw a red box */
for( i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ ) {
CvRect *r = ( CvRect* )cvGetSeqElem( faces, i );
cvRectangle( img,
cvPoint( r->x, r->y ),
cvPoint( r->x + r->width, r->y + r->height ),
CV_RGB( 255, 0, 0 ), 1, 8, 0 );
}
/* display video */
cvShowImage( "video", img );
}
void detectupperbody( IplImage *img1 )
{
int i;
/* detect faces */
CvSeq *body = cvHaarDetectObjects(
img1,
upperbodyCascade,
upperbodyStorage,
1.2,
2,
1/*CV_HAAR_DO_CANNY_PRUNNING*/,
cvSize( 0, 0 ) );
/* for each face found, draw a red box */
for( i = 0 ; i < ( body ? body->total : 0 ) ; i++ ) {
CvRect *r = ( CvRect* )cvGetSeqElem( body, i );
cvRectangle( img1,
cvPoint( r->x, r->y ),
cvPoint( r->x + r->width, r->y + r->height ),
CV_RGB( 255, 255, 255 ), 1, 8, 0 );
}
/* display video */
cvShowImage( "upperbody", img1 );
//cvWaitKey(30);
}
void detectlowerbody( IplImage *img1 )
{
int i;
/* detect faces */
CvSeq *body = cvHaarDetectObjects(
img1,
lowerbodyCascade,
lowerbodyStorage,
1.2,
2,
1/*CV_HAAR_DO_CANNY_PRUNNING*/,
cvSize( 1/4, 1/4 ) );
for( i = 0 ; i < ( body ? body->total : 0 ) ; i++ ) {
CvRect *r = ( CvRect* )cvGetSeqElem( body, i );
cvRectangle( img1,
cvPoint( r->x, r->y ),
cvPoint( r->x + r->width, r->y + r->height ),
CV_RGB( 0, 255,0 ), 1, 8, 0 );
}
/* display video */
cvShowImage( "lowerbody", img1 );
//cvWaitKey(30);
}
This is my code:
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
CvHaarClassifierCascade *cascade;
CvMemStorage *storage;
CvHaarClassifierCascade *upperbodyCascade;
CvMemStorage *upperbodyStorage;
CvHaarClassifierCascade *lowerbodyCascade;
CvMemStorage *lowerbodyStorage;
void detectFaces( IplImage *img );
void detectupperbody( IplImage *img );
void detectlowerbody( IplImage *img );
IplImage *bframe = 0;
IplImage *resframe=0;
int main( int argc, char** argv )
{
CvCapture *capture;
IplImage *frame;
int key;
char *filename = "haarcascade_frontalface_alt.xml";
char *upperbodyFilename ="haarcascade_fullbody.xml";
char *lowerbodyFilename ="haarcascade_lowerbody.xml";
/* load the classifier
note that I put the file in the same directory with
this code */
cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );
upperbodyCascade = ( CvHaarClassifierCascade* )cvLoad( upperbodyFilename, 0, 0, 0 );
lowerbodyCascade = ( CvHaarClassifierCascade* )cvLoad( lowerbodyFilename, 0, 0, 0 );
/* setup memory buffer; needed by the face detector */
storage = cvCreateMemStorage( 0 );
upperbodyStorage = cvCreateMemStorage( 0 );
lowerbodyStorage = cvCreateMemStorage( 0 );
/* initialize camera */
capture = cvCaptureFromCAM( 0 );
/* always check */
assert( cascade && storage && capture );
assert( upperbodyCascade && upperbodyStorage && capture );
assert( lowerbodyCascade && lowerbodyStorage && capture );
/* create a window */
cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "upperbody", CV_WINDOW_AUTOSIZE );
cvNamedWindow( "lowerbody",CV_WINDOW_AUTOSIZE );
while( key != 'q' ) {
/* get a frame */
frame = cvQueryFrame( capture );
/* always check */
if( !frame ) break;
/* 'fix' frame */
cvFlip( frame, frame, 1 );
frame->origin = 0;
/* detect faces and display video */
detectFaces(frame);
detectupperbody(frame);// FUNCTION IRE
detectlowerbody(frame); // FUNCTION IRE
/* quit if user press 'q' */
key = cvWaitKey( 10 );
}
/* free memory */
cvReleaseCapture( &capture );
cvDestroyWindow( "video" );
cvDestroyWindow( "upperbody" );
cvDestroyWindow( "lowerbody" );
cvReleaseHaarClassifierCascade( &cascade );
cvReleaseMemStorage( &storage );
return 0;
}
void detectFaces( IplImage *img )
{
int i;
/* detect faces */
CvSeq *faces = cvHaarDetectObjects(
img,
cascade,
storage,
1.1,
3,
0 /*CV_HAAR_DO_CANNY_PRUNNING*/,
cvSize( 40, 40 ) );
/* for each face found, draw a red box */
for( i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ ) {
CvRect *r = ( CvRect* )cvGetSeqElem( faces, i );
cvRectangle( img,
cvPoint( r->x, r->y ),
cvPoint( r->x + r->width, r->y + r->height ),
CV_RGB( 255, 0, 0 ), 1, 8, 0 );
}
/* display video */
cvShowImage( "video", img );
}
void detectupperbody( IplImage *img1 )
{
int i;
/* detect faces */
CvSeq *body = cvHaarDetectObjects(
img1,
upperbodyCascade,
upperbodyStorage,
1.2,
2,
1/*CV_HAAR_DO_CANNY_PRUNNING*/,
cvSize( 0, 0 ) );
/* for each face found, draw a red box */
for( i = 0 ; i < ( body ? body->total : 0 ) ; i++ ) {
CvRect *r = ( CvRect* )cvGetSeqElem( body, i );
cvRectangle( img1,
cvPoint( r->x, r->y ),
cvPoint( r->x + r->width, r->y + r->height ),
CV_RGB( 255, 255, 255 ), 1, 8, 0 );
}
/* display video */
cvShowImage( "upperbody", img1 );
//cvWaitKey(30);
}
void detectlowerbody( IplImage *img1 )
{
int i;
/* detect faces */
CvSeq *body = cvHaarDetectObjects(
img1,
lowerbodyCascade,
lowerbodyStorage,
1.2,
2,
1/*CV_HAAR_DO_CANNY_PRUNNING*/,
cvSize( 1/4, 1/4 ) );
for( i = 0 ; i < ( body ? body->total : 0 ) ; i++ ) {
CvRect *r = ( CvRect* )cvGetSeqElem( body, i );
cvRectangle( img1,
cvPoint( r->x, r->y ),
cvPoint( r->x + r->width, r->y + r->height ),
CV_RGB( 0, 255,0 ), 1, 8, 0 );
}
/* display video */
cvShowImage( "lowerbody", img1 );
//cvWaitKey(30);
}