Abhinav Jha
Abhinav Jha

Reputation: 53

How to properly instantiate CIDetector class object in iOS 5 face detection API

reading the Apple's documentation i tried using it's new face detection API but with no luck,, although there are no compile or runtime errors the instance method featuresInImage always return an array of CIFeature objects with null values.

First timer on stackoverflow, still tried my best to be short and specific.

Upvotes: 0

Views: 3362

Answers (2)

Abhinav Jha
Abhinav Jha

Reputation: 53

A minimal code (working) to test out the new iOS 5 face detection API

- (void)viewDidLoad{

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

CIImage *ciImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"IMG_0056.JPG"]];

NSLog(@"showing image now");
//[imageView setImage:image];


if (ciImage == nil)
    NSLog(@"CIImage is nil");


//imageView.image = [UIImage imageWithCGImage:[context createCGImage:ciImage fromRect:ciImage.extent]];
[imageView setImage:[UIImage imageNamed:@"IMG_0056.JPG"]];

NSDictionary *options = [[NSDictionary alloc] initWithObjectsAndKeys:
                         @"CIDetectorAccuracy", @"CIDetectorAccuracyHigh",nil];
CIDetector *ciDetector = [CIDetector detectorOfType:CIDetectorTypeFace 
                                            context:nil
                                            options:options];
NSArray *features = [ciDetector featuresInImage:ciImage];
NSLog(@"no of face detected: %d", [features count]);
NSString *myString = [[NSString alloc] initWithFormat:@"%d face(s) detected\n",[features count]];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Face detection" message:myString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];

}

Upvotes: 4

SomeGuy
SomeGuy

Reputation: 9690

UIImage* uiimage = nil;
CIImage* image = [CIImage imageWithCGImage:uiimage.CGImage];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];

See here for full tutorial http://b2cloud.com.au/how-to-guides/face-detection-in-ios-5

Upvotes: 2

Related Questions