Вопрос

Im working on an iPhone app where Im trying to implement CIDetectorEyeBlink to check if the person in the image has closed eyes. But the leftEyeClosed and rightEyeClosed properties always return 0/NO.

I pasted some of the my code for implementation.

 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");
}
Это было полезно?

Решение

I was having the same issue but after trying out this tutorial I realized that I was not adding the: CIDetectorImageOrientation option for example:

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] }];

Now it works smooth ;)

Другие советы

There's nothing wrong with your code. The blink detector will succeed on some images and fail on others, rather inconsistently. Try for yourself on several images.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top