顔の領域内にのみ入る目を検出しようとしているため、コードにいくつかの小さな変更を加えました。
if( cascade )
{
double t = (double)cvGetTickCount();
CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storage,
1.1, 2, 0|CV_HAAR_DO_CANNY_PRUNING,
cvSize(30, 30) );
t = (double)cvGetTickCount() - t;
printf( "detection time = %gms\n", t/((double)cvGetTickFrequency()*1000.) );
for( i = 0; i < (faces ? faces->total : 0); i++ )
{
CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
CvMat small_img_roi;
CvSeq* nested_objects;
CvPoint center;
CvPoint center_1;
CvScalar color = colors[i%8];
int radius,radius_1;
center.x = cvRound((r->x + r->width*0.5)*scale);
center.y = cvRound((r->y + r->height*0.5)*scale);
radius = cvRound((r->width + r->height)*0.25*scale);
cvCircle( img, center, radius, color, 3, 8, 0 );
if( !nested_cascade )
continue;
else
printf("not continuing!\n");
cvGetSubRect( small_img, &small_img_roi, *r );
nested_objects = cvHaarDetectObjects( &small_img_roi, nested_cascade, storage,
1.1, 2, 0
|CV_HAAR_DO_CANNY_PRUNING, ,
cvSize(0, 0) );
for( j = 0; j < (nested_objects ? nested_objects->total : 0); j++ )
{
printf("start of nested objects loop!\n");
CvRect* nr = (CvRect*)cvGetSeqElem( nested_objects, j );
center_1.x = cvRound((r->x + nr->x + nr->width*0.5)*scale);
center_1.y = cvRound((r->y + nr->y + nr->height*0.5)*scale);
radius_1 = cvRound((nr->width + nr->height)*0.25*scale);
if(center_1.x+radius_1<center.x+radius&& center.x-radius<center_1.x-radius_1 && center_1.y<center.y+radius&& center.y<center_1.y+radius )
{
cvCircle( img, center_1, radius_1, color, 3, 8, 0 );
}
else
printf("cant find thy eyes!\n");
}
しかし、それはあまり成功しませんでした。デバッグしようとして、顔の円を描いている部分をコメントアウトしてみたところ、円がまったく描かれませんでした。これにより、オブジェクトがネストされた部分が機能していない可能性があるという結論に至りました。したがって、コードにいくつかの printfs を実装し、コンソールを監視しました。しかし、コンソールを観察した後、ネストされたオブジェクトの一部が実際に機能していないという結論に達しました。ただし、ネストされたオブジェクトの部分が顔検出部分に似ていたため、なぜそうなのかはまだわかりません。したがって、顔検出部分が機能する場合、ネストされたオブジェクト コードも機能するのではないでしょうか?
(>_<)