我设法执行了一些简单的面部和眼睛检测/跟踪。它不太准确,但它的工作原理。我想知道OpenCV库中是否有某种方法可以在移动时提取眼睛和脸部的坐标,并在控制台中实时打印出来。或者甚至可以将这些坐标保存在输出文件中。
更新(面部和眼部检测代码):
int detect( IplImage* img, const char* cascade_name )
{
static CvMemStorage* storage = 0;
static CvHaarClassifierCascade* cascade = 0;
int scale = 1;
int i;
IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
//Load Cascade
cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
if( !cascade )
{
fprintf( stderr, "ERROR: Could not load classifier cascade!\n" );
return 0;
}
storage = cvCreateMemStorage(0);
cvClearMemStorage( storage );
int faceDetected = 0;
if( cascade )
{
//In case there is more than one face
CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,
1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
cvSize(40, 40) );
faceDetected = (faces ? faces->total : 0);
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
//Maybe this is where I get the coordinates?
pt1.x = r->x*scale;
pt2.x = (r->x+r->width)*scale;
pt1.y = r->y*scale;
pt2.y = (r->y+r->height)*scale;
//Draw rectangle over face
cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
}
}
cvReleaseImage( &temp );
return faceDetected;
static CvMemStorage* storage = 0;
static CvHaarClassifierCascade* cascade = 0;
int scale = 1;
int i;
IplImage* temp = cvCreateImage( cvSize(img->width/scale,img->height/scale), 8, 3 );
答案 0 :(得分:3)
这可能是你想要的:
for( i=0 ; i< faces->total; i++ )
{
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
printf("( %d %d ) , ( %d %d) ", r->x, r->y, r->x + r->width, r->y + r->height );
}
答案 1 :(得分:0)
This是一个用opencv构建的简单面部检测。他们用另一个CascadeClassifier
检测面部内的眼睛。您可以从opencv repository下载现有CascadeClassifiers
的列表,并根据您的需要使用它们。如果它们都不满足您的要求,您可以随时训练自己的分类器,例如关注this tutorial。