使用OpenCv在IOS中裁剪圆形图像

使用OpenCv在IOS中裁剪圆形图像

本文介绍了使用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.

此掩码可以是二进制,这意味着它表示像素是否可见,或者它可以是 alpha-掩码表示其中任何像素的透明度, 0 表示不可见像素和(对于8位掩模图像) 255 表示完全不透明度。

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.

在上面的示例中,您可以获得子图像ROI(Region-Of-Interest),如下所示:

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

请注意 eyeImg 是不是副本,而是指 image 中的相同像素。如果你想要一个副本,最后添加一个 .clone()

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.

这篇关于使用OpenCv在IOS中裁剪圆形图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 17:10