3

我正在开发一个 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");
}
4

2 回答 2

9

我遇到了同样的问题,但是在尝试了本教程后,我意识到我没有添加: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] }];

现在它工作顺利;)

于 2014-05-26T20:30:42.503 回答
0

你的代码没有问题。眨眼检测器会在某些图像上成功,而在其他图像上失败,相当不一致。自己尝试几张图片。

于 2013-10-31T15:35:37.213 回答