【问题标题】:How can i detect face in an image using core image accurately in iOS?如何在 iOS 中使用核心图像准确检测图像中的人脸?
【发布时间】:2013-11-13 03:29:46
【问题描述】:

在我的应用程序中,我需要准确检测图像的面部,但我没有得到准确的输出。我使用了coreimage框架。我没有在其他地方得到右眼位置、左眼位置和嘴巴位置,甚至没有检测到微笑。

这是我的示例代码。

- (void)drawRect
{
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];

    CIImage *img=[CIImage imageWithCGImage:imageView.image.CGImage];
    NSArray* features = [detector featuresInImage:img];

    for (CIFaceFeature *feature in features)
    {
       CGRect faceRect = feature.bounds;

UIView* face = [[UIView alloc] initWithFrame:faceRect];

        [face setBackgroundColor:[[UIColor yellowColor] colorWithAlphaComponent:0.4]];
        [imageView addSubview:face];

        if(feature.hasLeftEyePosition)
        {
            UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(feature.leftEyePosition.x,feature.leftEyePosition.y, 20, 20)];
            [eye setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.2]];
            [eye setCenter:feature.leftEyePosition];
            [mainView addSubview:eye];

        }

        if(feature.hasRightEyePosition)
        {
            UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(feature.rightEyePosition.x, feature.rightEyePosition.y, 20, 20)];
            [eye setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.2]];
            [eye setCenter:feature.rightEyePosition];
            [mainView addSubview:eye];

        }

        if(feature.hasMouthPosition)
        {
            UIView* mouth = [[UIView alloc] initWithFrame:CGRectMake(feature.mouthPosition.x, feature.mouthPosition.y, 20, 20)];
            [mouth setBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.2]];
            [mouth setCenter:feature.mouthPosition];
            [mainView addSubview:mouth];

        }
        if(feature.hasSmile)
        {
            NSLog(@"you are smiling");
        }

    }

}

【问题讨论】:

  • 可能你的画质太差了?如果 CoreImage 找不到它,那么您不太可能使用任何其他方法。
  • 即使我尝试了高质量的图像,对于某些图像也没有检测到人脸。@borrden
  • “一些图片。”人脸检测不是一件小事。有时由于某种原因(奇怪的光线、奇怪的角度等)无法检测到人脸
  • 好的,谢谢博尔登

标签: ios iphone ios5 ios6 ios7


【解决方案1】:

在y轴上翻转图像以匹配核心图像使用的坐标系,从而获得准确的位置

【讨论】:

    猜你喜欢
    • 2013-10-01
    • 2021-06-18
    • 2013-01-23
    • 2020-08-24
    • 2019-12-01
    • 2021-06-26
    • 2020-12-07
    • 2014-04-28
    • 2015-03-11
    相关资源
    最近更新 更多