0

*****EDIT******

I was just doing some testing to see if I was missing something and it turns out the imgHolder.image is returning null but it is displaying an image. I am calling this on [void viewDidLoad].

*****EDIT******

I'm creating a simple application that you take a picture with, then it passes that image to another view controller and tries detecting your face in the image. I've tried using many tutorials, and googling the problem but I have no found a solution. The problem is that it will not detect any features no matter how many times I change the code or try another picture. A few of the tutorials I've tried are listed below along with my code.

CIImage* image = [CIImage imageWithCGImage:imgHolder.image.CGImage];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
NSDictionary *imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6]
                                                         forKey:CIDetectorImageOrientation];
NSArray* features = [detector featuresInImage:image options:imageOptions];
for(CIFaceFeature* feature in features)
{
    UIView* face = [[UIView alloc] initWithFrame:feature.bounds];
    [face setBackgroundColor:[[UIColor yellowColor] colorWithAlphaComponent:0.4]];
    [self.view.window addSubview:face];

    if(feature.hasLeftEyePosition)
    {
        UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
        [eye setBackgroundColor:[[UIColor blueColor] colorWithAlphaComponent:0.2]];
        [eye setCenter:feature.leftEyePosition];
        [self.view.window addSubview:eye];
    }

    if(feature.hasRightEyePosition)
    {
        UIView* eye = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
        [eye setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.2]];
        [eye setCenter:feature.rightEyePosition];
        [self.view.window addSubview:eye];
    }

    if(feature.hasMouthPosition)
    {
        UIView* mouth = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
        [mouth setBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.2]];
        [mouth setCenter:feature.mouthPosition];
        [self.view.window addSubview:mouth];
    }
}
NSLog(@"%d", features.count);

http://www.tokbox.com/blog/fun-with-core-graphics-in-ios/ http://b2cloud.com.au/how-to-guides/face-detection-in-ios-5 CIDetector and UIImagePickerController

Community
  • 1
  • 1
Destiny Dawn
  • 1,457
  • 3
  • 15
  • 29
  • 1
    Have you tried the Stanford iTunes U course? The session on AVFoundations by Salik Sayed has you ID a face then apply glasses. It might help. It's the third Friday session. – Douglas Dec 31 '12 at 02:41
  • @Douglas please check the edited version of this. I found out a little more information. – Destiny Dawn Dec 31 '12 at 02:43
  • I've just answered here http://stackoverflow.com/q/23016059/242882. Maybe it can help you. – Volodymyr B. Apr 11 '14 at 15:31

0 Answers0