2011-11-16 83 views
12

我正在致力於一個項目旨在軌道眼睛瞳孔。爲此,我製作了一個捕捉眼睛圖像的頭戴式系統。硬件部分完成我在軟件部分。我正在使用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等)。這是可行嗎?如果是,我應該如何繼續?

回答

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() 

Here are the results.

所以你的下一個步驟是使用某種跟蹤器,像一個Kalmann濾波器,能夠穩健地追蹤瞳孔。您可能需要將眼睛建模爲球體,並在球體座標(即theta和phi)中跟蹤瞳孔的質心。您還需要編寫一些代碼來檢測眨眼事件,以便在用戶眨眼時系統不會全部失效。我建議使用canny邊緣檢測器來查找圖像中最大的水平線,並假設這些是眼瞼。我希望這可以幫助,請讓我們知道你的工作進展。

2

這一切都取決於你的系統必須有多好。如果這是一個爲期兩個月的大學項目,那麼可以像Kscottz推薦的那樣找到並跟蹤一些斑點或使用現成的解決方案。

但是,如果你的目標是要有一個更嚴重的系統,你必須更深入。

我建議你的方法是檢測臉部興趣點。一個很好的例子是主動外觀模型,這似乎是最好的跟蹤面臨

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

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

它需要你的計算機視覺算法有深刻的理解,良好的編程技巧,還有一些工作。但結果是值得的。

不要被演示顯示全臉跟蹤的事實所迷惑。你可以訓練它來跟蹤什麼:手,眼,花或葉,等

(AAM與開始之前,你可能想了解更多關於其它臉部追蹤算法,他們可能對你更好。)

1

這是我的解決方案,我能夠跟蹤眼睛並精確地找到瞳孔的中心座標。

首先我對頭戴式攝像頭拍攝的圖像進行閾值處理。之後,我使用輪廓查找算法,然後找到所有輪廓的質心。這給我眼睛瞳孔的中心座標,這種方法實時工作正常,還能以非常高的準確度檢測眨眼。

+0

這真的應該是一個新問題。 –

+0

好的,這裏是http://stackoverflow.com/questions/8200031/transfer-output-of-opencv-to-input-for-a-game-engine – siso