13

我正在研究一个旨在跟踪眼睛瞳孔的项目。为此,我制作了一个头戴式系统,可以捕捉眼睛的图像。完成了硬件部分,我对软件部分感到震惊。我正在使用opencv。请让我知道跟踪学生的最有效方法是什么。Houghcircles表现不佳。

之后我也尝试过使用HSV过滤器,这里是原始图像的截图和处理过的代码和链接。请帮我解决这个问题。该链接还包含我在此代码中使用的眼瞳视频。

https://picasaweb.google.com/118169326982637604860/16November2011?authuser=0&authkey=Gv1sRgCPKwwrGTyvX1Aw&feat=directlink

代码:

include "cv.h"

include"highgui.h"

IplImage* GetThresholdedImage(IplImage* img)
{

    IplImage *imgHSV=cvCreateImage(cvGetSize(img),8,3);
    cvCvtColor(img,imgHSV,CV_BGR2HSV);
    IplImage *imgThresh=cvCreateImage(cvGetSize(img),8,1);
    cvInRangeS(imgHSV,cvScalar(0, 84, 0, 0),cvScalar(179, 256, 11, 0),imgThresh);
    cvReleaseImage(&imgHSV);
    return imgThresh;
}

void main(int *argv,char **argc)
{

    IplImage *imgScribble= NULL;
    char c=0;
    CvCapture *capture;
    capture=cvCreateFileCapture("main.avi");

    if(!capture)
    {
        printf("Camera could not be initialized");
        exit(0);
    }
    cvNamedWindow("Simple");
    cvNamedWindow("Thresholded");

    while(c!=32)
    {
        IplImage *img=0;
        img=cvQueryFrame(capture);
        if(!img)
            break;
        if(imgScribble==NULL)
            imgScribble=cvCreateImage(cvGetSize(img),8,3);

        IplImage *timg=GetThresholdedImage(img);
        CvMoments *moments=(CvMoments*)malloc(sizeof(CvMoments));
        cvMoments(timg,moments,1);

        double moment10 = cvGetSpatialMoment(moments, 1, 0);
        double moment01 = cvGetSpatialMoment(moments, 0, 1);
        double area = cvGetCentralMoment(moments, 0, 0);

        static int posX = 0;
        static int posY = 0;

        int lastX = posX;
        int lastY = posY;

        posX = moment10/area;
        posY = moment01/area;
         // Print it out for debugging purposes
        printf("position (%d,%d)\n", posX, posY);
        // We want to draw a line only if its a valid position
        if(lastX>0 && lastY>0 && posX>0 && posY>0)
        {
            // Draw a yellow line from the previous point to the current point
            cvLine(imgScribble, cvPoint(posX, posY), cvPoint(lastX, lastY), cvScalar(0,255,255), 5);
        }
        // Add the scribbling image and the frame...

        cvAdd(img, imgScribble, img);

        cvShowImage("Simple",img);
        cvShowImage("Thresholded",timg);
        c=cvWaitKey(3);
        cvReleaseImage(&timg);
        delete moments;

    }
    //cvReleaseImage(&img);
    cvDestroyWindow("Simple");
    cvDestroyWindow("Thresholded");

}

我能够跟踪眼睛并精确找到瞳孔的中心坐标。

首先,我对头戴式相机拍摄的图像进行阈值处理。之后我使用了轮廓查找算法,然后我找到了所有轮廓的质心。这给了我眼睛瞳孔的中心坐标,这种方法可以实时正常工作,并且可以非常准确地检测眨眼。

现在,我的目标是将此功能嵌入到游戏(赛车游戏)中。如果我向左/向右看,那么汽车会向左/向右移动,如果我眨眼,汽车就会减速。我现在怎么继续???我需要一个游戏引擎来做到这一点吗?

我听说过一些与visual studio 2010(unity 等)兼容的开源游戏引擎。可行吗???如果是,我应该如何进行?

4

3 回答 3

10

我是 SimpleCV 的开发者之一。我们维护一个用于计算机视觉的开源 Python 库。您可以在SimpleCV.org下载它。SimpleCV 非常适合通过在命令行上破解来解决这些类型的问题。我只用几行代码就能提取出瞳孔。干得好:

img = Image("eye4.jpg") # load the image
bm = BlobMaker() # create the blob extractor
# invert the image so the pupil is white, threshold the image, and invert again
# and then extract the information from the image
blobs = bm.extractFromBinary(img.invert().binarize(thresh=240).invert(),img)

if(len(blobs)>0): # if we got a blob
    blobs[0].draw() # the zeroth blob is the largest blob - draw it
    locationStr = "("+str(blobs[0].x)+","+str(blobs[0].y)+")"
    # write the blob's centroid to the image
    img.dl().text(locationStr,(0,0),color=Color.RED)
    # save the image
    img.save("eye4pupil.png")
    # and show us the result.
    img.show()

这是结果。

因此,您接下来的步骤是使用某种跟踪器,例如卡尔曼滤波器,来稳健地跟踪瞳孔。您可能希望将眼睛建模为球体并在球坐标(即 theta 和 phi)中跟踪瞳孔的质心。您还需要编写一些代码来检测眨眼事件,这样系统就不会在用户眨眼时出现问题。我建议使用精巧的边缘检测器来找到图像中最大的水平线,并假设这些是眼睑。我希望这会有所帮助,请让我们知道您的工作进展如何。

于 2011-11-16T03:36:40.660 回答
2

这完全取决于您的系统必须有多好。如果这是一个为期 2 个月的大学项目,那么按照 Kscottz 的建议,可以找到并跟踪一些 blob 或使用现成的解决方案。

但如果你的目标是拥有一个更严肃的系统,你必须更深入。

我向您推荐的一种方法是检测人脸兴趣点。一个很好的例子是 Active Appearance Models,它似乎最擅长跟踪面部

http://www2.imm.dtu.dk/~aam/

http://www.youtube.com/watch?v=M1iu__viJN8

它需要您对计算机视觉算法有扎实的了解、良好的编程技能和一些工作。但结果将是值得的。

不要被演示显示全脸跟踪的事实所迷惑。你可以训练它跟踪任何东西:手、眼睛、花朵或树叶等。

(在开始使用 AAM 之前,您可能想了解更多关于其他人脸跟踪算法的信息。它们可能更适合您)

于 2011-11-16T06:52:03.157 回答
1

这是我的解决方案,我能够跟踪眼睛并精确找到瞳孔的中心坐标。

首先,我对头戴式相机拍摄的图像进行阈值处理。之后我使用了轮廓查找算法,然后我找到了所有轮廓的质心。这给了我眼睛瞳孔的中心坐标,这种方法可以实时正常工作,并且可以非常准确地检测眨眼。

于 2011-11-20T04:04:53.107 回答