跟踪视频中的眼球瞳孔

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等)。这可行吗?如果可以,我该如何操作?
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()

这里是结果。

所以你接下来需要使用某种追踪器,例如卡尔曼滤波器,来稳健地追踪瞳孔。你可能希望将眼睛建模为一个球体,并在球坐标系(即θ和φ)中跟踪瞳孔的质心。您还需要编写一些代码来检测眨眼事件,以便系统在用户眨眼时不会出现问题。我建议使用Canny边缘检测器查找图像中最大的水平线,并假设它们是眼睑。希望这能有所帮助,请告诉我们您的工作进展情况。


2
这一切取决于你的系统需要多好。如果只是一个为期两个月的大学项目,找到和跟踪一些斑点或使用Kscottz推荐的现成解决方案就可以了。
但是,如果你想要一个更严肃的系统,你必须深入研究。
我建议你采用的方法是检测人脸的重点。一个很好的例子是Active Appearance Models,它似乎是跟踪人脸最好的方法。

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

并且

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

需要具备扎实的计算机视觉算法理解、良好的编程技能和一定的工作量。但努力付出的成果将是值得的。
不要被演示中展示的整脸追踪所迷惑。您可以对其进行训练,以追踪任何东西:手、眼睛、花或叶子等。
(在开始使用AAM之前,您可能希望阅读更多关于其他面部追踪算法的内容。它们可能更适合您)

1

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

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


这确实应该是一个新问题。 - Mark Hall
好的,这里是翻译内容:http://stackoverflow.com/questions/8200031/transfer-output-of-opencv-to-input-for-a-game-engine - siso

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接