2014-10-08 72 views
2

我在圖像中,中心左眼(X,Y)和中心右眼(X,Y)有兩個點。我用cv::circle畫了兩隻眼睛的圓圈,這很好。但我現在想要做的是獲得我繪製的圈子的投資回報率,即提取眼睛並將它們保存在新的Mat中。從圓圈/點獲取投資回報率

這是我目前的結果是:

...但正如我上面所說的,只需要在提取眼睛周圍的圓圈進入一個新的墊,每隻眼睛一個工作。

這是我的代碼:

cv::Mat plotImage; 

plotImage = cv::imread("C:/temp/face.jpg", cv::IMREAD_COLOR); 

cv::Point leftEye(person.GetLeftEyePoint().X, person.GetLeftEyePoint().Y); 
cv::Point rightEye(person.GetRightEyePoint().X, person.GetRightEyePoint().Y); 

cv::circle(plotImage, leftEye, 15, cv::Scalar(255, 255)); 
cv::circle(plotImage, rightEye, 15, cv::Scalar(255, 255)); 

cv::imwrite("C:\\temp\\plotImg.jpg", plotImage); 

我發現下面的鏈接,但我似乎無法讓他們感覺/它們應用到我想要做的事: http://answers.opencv.org/question/18784/crop-image-using-hough-circle/

Selecting a Region OpenCV

Define image ROI with OpenCV in C

任何幫助/指導表示讚賞!謝謝!

+0

你是如何獲得積分? – berak 2014-10-08 07:33:46

+0

我正在使用分析/發現中心眼點的SDK。我創建了自己的Person類來獲取/設置這些值。 – LKB 2014-10-08 07:37:29

回答

7

讓我們將他限制在一個眼睛簡單:

enter image description here

// (badly handpicked coords): 
Point cen(157,215); 
int radius = 15; 

//get the Rect containing the circle: 
Rect r(cen.x-radius, cen.y-radius, radius*2,radius*2); 

// obtain the image ROI: 
Mat roi(plotImage, r); 

// make a black mask, same size: 
Mat mask(roi.size(), roi.type(), Scalar::all(0)); 
// with a white, filled circle in it: 
circle(mask, Point(radius,radius), radius, Scalar::all(255), -1); 

// combine roi & mask: 
Mat eye_cropped = roi & mask; 

enter image description here

+0

非常聰明!非常感謝。 :) – LKB 2014-10-08 08:28:54

+0

不確定,如果你真的想要圓形面具。否則,'roi'已經是答案。 – berak 2014-10-08 08:30:50

+1

所以我使用eye_cropped(合成的roi&mask)圖像進行分析,看看眼睛是否是紅色的(所以我只想分析這個圓圈本身)。這是可以的,因爲圓的外面(Rect)是黑色的。但是,現在我將eye_cropped圖像合併回主圖像,由於周圍的黑色Rect,這是一個問題。我將如何去除外部黑色,這樣我就可以將眼睛(我改變了眼睛的顏色)合併到主圖像上了? 'roi.copyTo(plotImage(cv :: Rect(person.GetLeftEyePoint()。X,person.GetLeftEyePoint()。Y,roi.cols,roi.rows)));' – LKB 2014-10-10 07:03:40