0

I am developing face features detection in my project.

Heretofore i have developed detecting the face, then finding the eyes within the face. I want to crop the eyes which are in circular .

   circle( mask, center, radius, cv::Scalar(255,255,255), -1, 8, 0 ); 
                  image.copyTo( dst, mask ); 

Here in the above code , I am able to Mask image with black color leaving eye region. now I am want to crop only the Eye region.

Can anybody help me out on this issue.Please check below image

enter image description here

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
sneha
  • 7
  • 1
  • 6

1 Answers1

0

Cropping, by definition, means cutting an axis aligned rectangle from a larger image, leaving a smaller image.

If you want to "crop" a non-axis-aligned rectangle, you will have to use a mask. The mask can be the size of the full image (this is sometimes convenient), or as small and the smallest bounding (axis-aligned) rectangle containing all the pixels you want to leave visible.

This mask can be binary, meaning that it indicates whether or not a pixel is visible, or it can be an alpha-mask which indicated the degree of transparency of any pixel within it, with 0 indicating a non-visible pixel and (for 8-bit mask image) 255 indicating full opacity.

In your example above you can get the sub-image ROI (Region-Of-Interest) like this:

cv::Mat eyeImg = image(cv::Rect(center.x - radius, // ROI x-offset, left coordinate
                                center.y - radius, // ROI y-offset, top coordinate 
                                2*radius,          // ROI width
                                2*radius));        // ROI height

Note that eyeImg is not a copy, but refers to the same pixels within image. If you want a copy, add a .clone() at the end.

Adi Shavit
  • 16,743
  • 5
  • 67
  • 137
  • Ok can you tell me how to crop only eye region in the above image ? – sneha Jan 13 '14 at 07:16
  • What would you like to do? Create a new smaller image containing the circle or creating a mask the size of the image? – Adi Shavit Jan 13 '14 at 07:24
  • I want to create new image , this image should be only Eye image . how to crop it . – sneha Jan 13 '14 at 07:45
  • I hope you got ? I have the rectangle of eyes , and from that i am getting center and radius and drawing the circle , then next i need only eye region as the image . – sneha Jan 13 '14 at 07:49
  • so you want a "round" image? standard computer images (like in openCV) are always rectangles sized width*height. – Micka Jan 13 '14 at 10:23
  • Yes i need the round eye image . – sneha Jan 15 '14 at 05:52