opencv 图片截取圆_使用OpenCv在IOS中裁剪圆形图像

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

解决方案

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值