【问题标题】:Can't detect face in images that capture by camera of Iphone无法在 iPhone 相机拍摄的图像中检测到人脸
【发布时间】:2016-01-17 22:50:09
【问题描述】:

我有问题。我使用2图像。一种是从网上下载。另一个是由 iPhone 的相机拍摄的。 我使用 CIDetector 来检测 2 张图像中的人脸。它在从互联网下载的图像中完美运行。但另一个,它无法检测或检测错误。

我检查了许多图像。结果是一样的。

【问题讨论】:

    标签: iphone ios image


    【解决方案1】:

    试试这个

       NSDictionary *options = [NSDictionary dictionaryWithObject: CIDetectorAccuracyLow            forKey: CIDetectorAccuracy];
            CIDetector  *detector = [CIDetector detectorOfType: CIDetectorTypeFace context:    nil options: options];
    
          CIImage *ciImage = [CIImage imageWithCGImage: [image CGImage]];
        NSNumber *orientation = [NSNumber numberWithInt:[image imageOrientation]+1];
        NSDictionary *fOptions = [NSDictionary dictionaryWithObject:orientation forKey: CIDetectorImageOrientation];
            NSArray *features = [detector featuresInImage:ciImage options:fOptions];
            for (CIFaceFeature *f in features) {
    
                NSLog(@"left eye found: %@", (f. hasLeftEyePosition ? @"YES" : @"NO"));
    
                NSLog(@"right eye found: %@", (f. hasRightEyePosition ? @"YES" : @"NO"));
    
                NSLog(@"mouth found: %@", (f. hasMouthPosition ? @"YES" : @"NO"));
    
                if(f.hasLeftEyePosition)
    
                    NSLog(@"left eye position x = %f , y = %f", f.leftEyePosition.x, f.leftEyePosition.y);
    
                if(f.hasRightEyePosition)
    
                    NSLog(@"right eye position x = %f , y = %f", f.rightEyePosition.x, f.rightEyePosition.y);
    
                if(f.hasMouthPosition)
    
                    NSLog(@"mouth position x = %f , y = %f", f.mouthPosition.x, f.mouthPosition.y);
    
            }
    

    如果您始终在纵向使用前置摄像头,请添加此

          NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber        numberWithInt:6] forKey:CIDetectorImageOrientation];
          NSArray* features = [detector featuresInImage:image options:imageOptions];
    

    更多信息

    示例:https://github.com/beetlebugorg/PictureMe

    iOS Face Detection Issue

    Face Detection issue using CIDetector

    https://stackoverflow.com/questions/4332868/detect-face-in-iphone?rq=1

    【讨论】:

    • 最大的问题是当我使用iPhone相机拍摄的图像时无法检测到
    • 但是如果我设置 NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation]; 无法检测到在互联网上下载的图像是否是风景…………:(
    • 以上方法你试过了吗?它现在是否适用于从 iPhone 捕获的图像?使用您用于面部检测的代码更新您的问题。
    • 我们能知道Iphone拍摄的图像是前置摄像头还是后置摄像头拍摄的吗?
    【解决方案2】:

    我尝试使用上面的代码。它可以检测由 Iphone 捕获的图像。但它无法检测到从 Internet 下载的图像。这是我的代码

    NSDictionary *options = [NSDictionary dictionaryWithObject: CIDetectorAccuracyLow            forKey: CIDetectorAccuracy];
    CIDetector  *detector = [CIDetector detectorOfType: CIDetectorTypeFace context:    nil options: options];
    
    CIImage *ciImage = [CIImage imageWithCGImage: [facePicture CGImage]];
    NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber        numberWithInt:6] forKey:CIDetectorImageOrientation];
    NSArray *features = [detector featuresInImage:ciImage options:imageOptions];
    

    当它检测到人脸时。我用代码显示

    for (CIFaceFeature *feature in features) {
    

    // // 设置红色特征颜色

        CGRect faceRect = [feature bounds];
    
        CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 0.5f);
        CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
        CGContextSetLineWidth(context, 2.0f * scale);
        CGContextAddRect(context, feature.bounds);
        CGContextDrawPath(context, kCGPathFillStroke);
        CGContextDrawImage(context, faceRect, [imgDraw CGImage]);
    

    位置不对。它向右移动一段距离。

    【讨论】:

    • 请将此添加到您的问题中。最好将其从答案中删除
    • 请稍候。更有经验的人会帮助你
    【解决方案3】:

    我遇到了同样的问题。您可以在检测前更改图像的大小。

    CGSize size = CGSizeMake(cameraCaptureImage.size.width, cameraCaptureImage.size.height);
    UIGraphicsBeginImageContext(size);
    [cameraCaptureImage drawInRect:CGRectMake(0, 0, size.width, size.height)];
    cameraCaptureImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    【讨论】:

      猜你喜欢
      • 2016-02-13
      • 1970-01-01
      • 2018-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      • 2016-09-22
      • 2019-08-02
      相关资源
      最近更新 更多