Getting ROI from a circle / point

I have two points in the image, a left eye in the center (X, Y) and a right right eye (X, Y). I drew circles around both eyes using cv::circle

and it is fine. But what I am currently trying to do is get the ROI of the circles I drew, that is, extract the eyes and save them in a new Mat.

This is my current result:

... But as I said above, you just need to work on extracting the circles around the eyes into a new "Mat", one for each eye.

This is my code:

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

      

I found the following links, but I can't figure them out / apply to what I'm trying to do: http://answers.opencv.org/question/18784/crop-image-using-hough-circle/

OpenCV region selection

Determine ROI of an Image with OpenCV in C

Any help / guidance is appreciated! Thank!

+3


source to share


1 answer


let it be limited to one eye for simplicity:

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

+8


source







All Articles