iphone - 使用 CIDetector 的人脸检测问题

标签 iphone objective-c ios face-detection

我正在开发一个应用程序,我必须在其中检测左眼、右眼和嘴巴的位置。 我的 self.view 上有一个 imageView 并且 imageView 包含一个面部图像,现在我想要同时获取眼睛和嘴巴的坐标。我已经看到了 2-3 个示例代码,但在所有代码中都大致相同,我们必须反转我的 View 以匹配我不想要的坐标,因为我的 View 有一些其他控件。还有一件事他们都在使用

UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image.png"]];

但是我的 imageView 有框架,我不能用图像初始化它。当我这样做时,我发现 faceFeature 的眼睛和嘴巴坐标是错误的。

我的代码是从 this sample code 开始的但在这个 View 中也正在反转其 Y 坐标。

任何人都可以帮助我如何在不反转我的 self.view 的情况下检测 UIImageView 图像上的面部眼睛和嘴巴位置。

如果我的问题不够清楚,请告诉我。

最佳答案

这里的技巧是将返回的点和边界从 CIDetector 转换为您的坐标,而不是翻转您自己的 View 。 CIImage 的原点位于左下角,您需要将其转换为左上角

int height = CVPixelBufferGetHeight(pixelBuffer);
CGAffineTransform transform = CGAffineTransformMakeScale(1, -1);
transform = CGAffineTransformTranslate(transform, 0, -1 * height);

/* Do your face detection */

CGRect faceRect = CGRectApplyAffineTransform(feature.bounds, transform);
CGPoint mouthPoint = CGPointApplyAffineTransform(feature.mouthPosition, transform);
// Same for eyes, etc

关于 UIImageView 的第二个问题,你只需要做

imageview.image = yourImage

初始化 ImageView 之后

关于iphone - 使用 CIDetector 的人脸检测问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154585/

相关文章:

android - 您可以将应用作为应用内购买来销售吗?

objective-c - NSImage 不缩放

ios - 搜索栏色调颜色

objective-c - @property 声明属性的顺序是否有公认的约定?

ios - CloudKit - NSPredicate 用于在引用列表中查找包含多个 CKReferences 的所有记录

ios - 关于 BOOL 方法信息的小请求

iphone - 模拟相机应用程序 'tap to focus'

iphone - 如何在Objective C代码中使用Class对象

iphone - 应用程序在前台时的 UILocalNotifications

ios 解析_user 指针等于用户id?