#include <CFaceDetect.h>
Public Member Functions | |
| CFaceDetect () | |
| Class Constructor. | |
| void | init (int cols, int lines) |
| Instance initialization function. | |
| void | close () |
| Deallocation function. | |
| int | detect (IplImage *in) |
| Face detection function. | |
| CvRect | getBigFace () |
| Detected faces sorting function. | |
| void | draw (IplImage *in) |
| Detected faces bounding boxes drawing function. | |
| CFaceDetect () | |
| Class Constructor. | |
| void | init (int cols, int lines, const char *fileName) |
| Instance initialization function. | |
| void | close () |
| Deallocation function. | |
| int | detect (IplImage *in) |
| Face detection function. | |
| CvRect | getBigFace () |
| Detected faces sorting function. | |
| CvRect | getLargestFace () |
| void | draw (IplImage *in) |
| Detected faces bounding boxes drawing function. | |
Data Fields | |
| CvMemStorage * | storage |
| CvHaarClassifierCascade * | cascade |
| CvSeq * | faces |
| IplImage * | mask |
| IplImage * | in_copy |
| IplImage * | fake_in |
| int | AreaGreater |
| int | area |
| CvRect | rect |
| CvRect | auxRect |
| bool | first |
| int | lostLag |
| CvRect | last_auxRect |
Static Public Attributes | |
| static const char * | cascade_name = "haarcascade_frontalface_alt.xml" |
Definition at line 17 of file CFaceDetect.h.
| CFaceDetect::CFaceDetect | ( | ) |
Class Constructor.
Creates an instance of class CFaceDetect. Don't forget to call init() to initialize all variables!
Changed in 14/03/07 by Júlio - email: jgomes@isr.ist.utl.pt Changes: nearest neighbourhood
Definition at line 27 of file CFaceDetect.cpp.
{
storage=0;
cascade=0;
mask = 0;
in_copy = 0;
cascade = 0;
storage = 0;
}
| CFaceDetect::CFaceDetect | ( | ) |
Class Constructor.
Creates an instance of class CFaceDetect. Don't forget to call init() to initialize all variables!
| void CFaceDetect::close | ( | void | ) |
Deallocation function.
Deallocates images and storage spaces.
Definition at line 73 of file CFaceDetect.cpp.
{
if (mask)
cvReleaseImage(&mask);
if (in_copy)
cvReleaseImage(&in_copy);
if (storage)
cvReleaseMemStorage(&storage);
}
| void CFaceDetect::close | ( | ) |
Deallocation function.
Deallocates images and storage spaces.
| int CFaceDetect::detect | ( | IplImage * | in | ) |
Face detection function.
Detects all faces in input image <in>. If <in> ROI is set, a fake header is created and <in> is processed only within that ROI. Returns the number of detected faces. NOTE: Input image <in> can be RGB (tested) or Grayscale (not tested yet).
| int CFaceDetect::detect | ( | IplImage * | in | ) |
Face detection function.
Detects all faces in input image <in>. If <in> ROI is set, a fake header is created and <in> is processed only within that ROI. Returns the number of detected faces. NOTE: Input image <in> can be RGB (tested) or Grayscale (not tested yet).
Definition at line 94 of file CFaceDetect.cpp.
{
cvClearMemStorage( storage );
if( cascade )
{
rect=cvGetImageROI(in);
// CREATE A FAKE IMAGE HEADER:
// DATA POINTS TO THE ORIGINAL DATA,
// BUT CV "THINKS" fake_in HAS DIFFERENT SIZE.
// __NEVER__ DEALLOCATE fake_in !!!
fake_in=cvCreateImageHeader( cvSize(rect.width, rect.height),
in->depth, in->nChannels);
fake_in->widthStep=in->widthStep;
fake_in->imageData=in->imageData+in->widthStep*rect.y+rect.x*in->nChannels;
// DEBUG
//cvNamedWindow( "Face Detect fake_in", 1 );
//cvShowImage( "Face Detect fake_in", fake_in );
// normal settings
//faces = cvHaarDetectObjects( fake_in, cascade, storage,
// 1.1, 3, 0,
// cvSize(40, 40) );
// real-time settings
//faces = cvHaarDetectObjects( fake_in, cascade, storage,
// 1.2, 2, CV_HAAR_DO_CANNY_PRUNING,
// cvSize(40, 40) );
// custom settings
//faces = cvHaarDetectObjects( fake_in, cascade, storage,
// 1.2, 2, CV_HAAR_DO_CANNY_PRUNING,
// cvSize(10, 10) );
// custom settings 2
faces = cvHaarDetectObjects( fake_in, cascade, storage,
1.4, 3, CV_HAAR_DO_CANNY_PRUNING,
cvSize(10, 10) ); //este ultimo parametro é o tamanho da BondingBox min
//para considerar a cara detectada
return faces->total;
}
else
{
printf("db: NOT CASCADE\n");
return -1;
}
}
| void CFaceDetect::draw | ( | IplImage * | in | ) |
Detected faces bounding boxes drawing function.
Draws bounding boxes of detected faces on image <in_copy> (an internal copy of <in> and marks those regions on binary image <mask>. If <in> ROI is set, a fake header is created and <in_copy> and <mask> are only processed within that ROI. IMPORTANT: CALL AFTER detect(), NOT BEFORE! IMPORTANT: input image <in> _MUST_ be the same as in detect()! NOTE: may be called before or after getBigFace(). NOTE: input image can be RGB (tested) or Grayscale (not tested yet).
Definition at line 193 of file CFaceDetect.cpp.
{
int scale = 1;
CvPoint pt1, pt2;
int i;
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
pt1.x = r->x*scale+rect.x;
pt2.x = (r->x+r->width)*scale+rect.x;
pt1.y = r->y*scale+rect.y;
pt2.y = (r->y+r->height)*scale+rect.y;
// draws red boxes on respective image
CvRect in_ROI=cvGetImageROI(in);
cvResetImageROI(in);
cvCopy(in, in_copy);
cvSetImageROI(in, in_ROI);
if (in_copy->nChannels==1)
cvRectangle( in_copy, pt1, pt2, cvScalar(255), 3, 8, 0 );
else if (in_copy->nChannels==3)
cvRectangle( in_copy, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
// draws filled white rectangles on respective mask
cvRectangle( mask, pt1, pt2, cvScalar(255), CV_FILLED, 8, 0 );
}
}
| void CFaceDetect::draw | ( | IplImage * | in | ) |
Detected faces bounding boxes drawing function.
Draws bounding boxes of detected faces on image <in_copy> (an internal copy of <in> and marks those regions on binary image <mask>. If <in> ROI is set, a fake header is created and <in_copy> and <mask> are only processed within that ROI. IMPORTANT: CALL AFTER detect(), NOT BEFORE! IMPORTANT: input image <in> _MUST_ be the same as in detect()! NOTE: may be called before or after getBigFace(). NOTE: input image can be RGB (tested) or Grayscale (not tested yet).
| CvRect CFaceDetect::getBigFace | ( | ) |
Detected faces sorting function.
Searches internal CvSeq <faces> for the face with greatest area. Stores bounding box in internal CvRect <auxRect> and returns it too. IMPORTANT: CALL AFTER detect(), NOT BEFORE!
| CvRect CFaceDetect::getBigFace | ( | ) |
Detected faces sorting function.
Searches internal CvSeq <faces> for the face with greatest area. Stores bounding box in internal CvRect <auxRect> and returns it too. IMPORTANT: CALL AFTER detect(), NOT BEFORE!
Definition at line 152 of file CFaceDetect.cpp.
{
int scale = 1;
CvPoint pt1, pt2;
int i;
AreaGreater=0;
auxRect=cvRect(0,0,0,0);
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
pt1.x = r->x*scale+rect.x;
pt2.x = (r->x+r->width)*scale+rect.x;
pt1.y = r->y*scale+rect.y;
pt2.y = (r->y+r->height)*scale+rect.y;
area=(pt2.x-pt1.x)*(pt2.y-pt1.y);
if (area>AreaGreater)
{
// CREATE RECT WITH GREATEST FACE BB
AreaGreater=area;
auxRect=cvRect(pt1.x,pt1.y,(pt2.x-pt1.x),(pt2.y-pt1.y));
}
}
return auxRect;
}
| void CFaceDetect::init | ( | int | cols, | |
| int | lines | |||
| ) |
Instance initialization function.
<cols> and <lines> are the dimensions of the largest images to be used by this instance.
Definition at line 46 of file CFaceDetect.cpp.
References cascade_name.
{
CvSize size = cvSize(cols,lines);
//<<<<<<< .mine
// mask = cvCreateImage( size, 8, 1 );
//=======
//printf("facedetect c\n");
mask = cvCreateImage( size, 8, 1 );
// printf("facedetect d\n");
//>>>>>>> .r115
in_copy = cvCreateImage( size, 8, 3 );
//<<<<<<< .mine
//cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
//=======
//printf("facedetect e\n");
cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
//>>>>>>> .r115
storage = cvCreateMemStorage(0);
}
| void CFaceDetect::init | ( | int | cols, | |
| int | lines, | |||
| const char * | fileName | |||
| ) |
Instance initialization function.
<cols> and <lines> are the dimensions of the largest images to be used by this instance.
Definition at line 55 of file CFaceDetect.cpp.
{
//printf("Init entered\n");
//printf("%s\n",fileName);
CvSize size = cvSize(cols,lines);
//<<<<<<< .mine
// mask = cvCreateImage( size, 8, 1 );
//=======
//printf("facedetect c\n");
mask = cvCreateImage( size, 8, 1 );
//printf("facedetect d\n");
//>>>>>>> .r115
in_copy = cvCreateImage( size, 8, 3 );
//<<<<<<< .mine
//cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
//=======
//printf("facedetect e\n");
//printf("Before loading cascade\n");
//cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
cascade = (CvHaarClassifierCascade*)cvLoad( fileName, 0, 0, 0 );
//>>>>>>> .r115
//printf("After loading cascade\n");
storage = cvCreateMemStorage(0);
}
static const char * CFaceDetect::cascade_name = "haarcascade_frontalface_alt.xml" [static] |
1.7.1