iOS 7功能:CIDetectorEyeBlink不会检测图像中的闭眼

时间:2013-09-20 13:33:20

标签: iphone ios7 core-image

我在iPhone应用程序上工作,我试图实现CIDetectorEyeBlink以检查图像中的人是否闭眼。但是LeftEyeClosed和rightEyeClosed属性总是返回0 / NO。

我粘贴了一些我的代码来实现。

 CIImage* image = [CIImage imageWithCGImage:originalImage.CGImage];

CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                          context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], CIDetectorEyeBlink, [NSNumber numberWithBool:YES], CIDetectorSmile, nil];

NSArray* features = [detector featuresInImage:image options:options];

for(CIFaceFeature* faceObject in features)
{
    NSLog(@"TEST left eyeblink: %@", faceObject.leftEyeClosed ? @"YES" : @"NO");
    NSLog(@"TEST right eyeblink: %@", faceObject.rightEyeClosed ? @"YES" : @"NO");
}

2 个答案:

答案 0 :(得分:8)

我遇到了同样的问题,但在尝试了这个tutorial后,我意识到我没有添加:CIDetectorImageOrientation选项,例如:

NSDictionary *detectorOptions = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh };
    CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:detectorOptions];

    NSArray *features = [faceDetector featuresInImage:[CIImage imageWithCGImage:_imageView.image.CGImage]
                                              options:@{ CIDetectorSmile : @YES,
                                                         CIDetectorEyeBlink : @YES,
                                                         CIDetectorImageOrientation :[NSNumber numberWithInt:ORIENTATION_NUMBER] }];

现在它工作顺利;)

答案 1 :(得分:0)

您的代码没有任何问题。眨眼检测器将在某些图像上成功并在其他图像上失败,而不是一致。在几张图片上尝试自己。