Cropping circular image in IOS using OpenCv

前端 未结 1 919
醉酒成梦
醉酒成梦 2021-01-16 18:25

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 eye

相关标签:
1条回答
  • 2021-01-16 18:40

    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.

    0 讨论(0)
提交回复
热议问题