Jason
Jason

Reputation: 13964

CIFaceFeature only works in LandscapeLeft

Following a tutorial from iTunes U on how to do face detection (the tutorial is only in the video, and not written online so I can't post a direct link). Basically, I have gotten face detection to work, but only if the phone is in LandscapeLeft mode.

Any ideas on why it works like that?

Upvotes: 0

Views: 506

Answers (1)

spring
spring

Reputation: 18497

Without seeing your code it's hard to say but my guess is that you are not setting CIDetectorImageOrientation? I've had detection fail when there was a mismatch between the image orientation and what the detector orientation is set to be.

Some code below - not cut 'n paste but more of a rough example.

- (void)detectFacialFeatures:(UIImage *)image withHighAccuracy:(BOOL) highAccuracy
{

CIImage* ciImage = [CIImage imageWithCGImage:sourceImage.CGImage];

if (ciImage == nil){
    printf("ugh \n");
    // bail
}

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    NSString *accuracy = highAccuracy ? CIDetectorAccuracyHigh : CIDetectorAccuracyLow;

    NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
                             CIDetectorAccuracyHigh, CIDetectorAccuracy,
                             orientation, CIDetectorImageOrientation,
                             nil];

    CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace 
                                              context:nil options:options];

    NSArray *features = [detector featuresInImage:ciImage];

    NSLog(@"features %@", features);

});
}

Upvotes: 4

Related Questions