面部内的眼睛检测 [英] Eye detection within face

查看:90
本文介绍了面部内的眼睛检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测仅落在面部区域内的眼睛,因此我对代码做了一些小的改动:

I am trying to detect eyes which only fall within the face region and hence I did some minor alterations to the code:

 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并监视了控制台.但是在观察了控制台之后,我得出的结论是,部分嵌套的对象确实不起作用.但是,由于嵌套对象部分与面部检测部分类似,我仍然不知道为什么如此.因此,如果面部检测部分起作用,嵌套的目标代码也应该起作用吗?

However, it wasn't very successful. In trying to debug it, I tried commenting off the part where they draw a circle for the face, which resulted in no circles at all being drawn. This led me to the conclusion that perhaps the part with nested objects was not working. Hence, I implemented several printfs in the code and monitored the console. But after observing the console, I came to the conclusion that indeed the part nested objects was not working. However, I am still clueless as to why this is so as the nested objects part was similar to the face detection portion. Hence, if the face detection portion works, shouldn't the nested object code work too?

(> _<)

推荐答案

请提供更多信息:

  1. 您正在使用哪个层叠文件?
  2. small_img的高度和宽度是多少?

关于您的代码:

  1. 您正在使用nested_cascade变量而不对其进行初始化.
  1. You are using nested_cascade variable without initializing it.

通常-尝试通过以下参数使用来自openCV的haarcascade_mcs_eyepair_big.xml文件:(图像,级联,存储,1.1、3、0,cvSize()),甚至使用scaleFactor参数的较小值.

Generally - try to use haarcascade_mcs_eyepair_big.xml file from openCV with this parameters: (image, cascade, storage, 1.1, 3, 0, cvSize()) or even with smaller value of scaleFactor parameter.

在撰写BSc论文(眼动追踪系统)期间,我做过类似的事情,但最终得到了非常简单的解决方案.刚开始时,我试图找到所有可以作为眼睛的对象",然后确定哪个是左眼,哪个是对,但是现在我不认为这是一个很好的解决方案.
最终,我决定尝试一次在脸内(haarcascade_frontalface_default.xml)内搜索两只眼睛(成对-来自opencv的haarcascade_mcs_eyepair_big.xml文件),我发现这是更好的解决方案.它更快,更简单(您不必确定要寻找的对象是什么—如果您试图使以前的眼睛位置过分笨拙,并且没有其他东西,则可能会非常复杂),并且易于实现.
精度对我来说足够好,速度也很高(整个系统-大约10-25fps-它取决于几件事).如果您想使用代码进行实时眼睛检测,我可以为您提供有关优化的更多详细信息.

I have done something similar during writing my BSc Thesis (Eyetracking system) and ended with quite easy solution. At the beginning i was trying to find inside face all 'objects' which can be eye and then decide which one is left eye and which one is right, but now i don't think it's a good solution.
Finally i decided to try to search for both eyes (pair - haarcascade_mcs_eyepair_big.xml file from opencv) at once inside face (haarcascade_frontalface_default.xml) and i find out that it's much better solution. It's faster, less complicated (you don't have to decide which object is the one you are looking for - it can be quite complicated if you try to have ragard previous positions of eyes and few other things) and easier to implement.
The accuracy was good enough for me and speed was quite high (whole system - about 10-25fps - it depends on few things). If you want to use your code for real-time eye detection i can give you few more details about optimization.

这篇关于面部内的眼睛检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆