1

I have used the below code to detect face from an image:

-(void)markFaces:(UIImageView *)imagePick {

CIImage* image = [CIImage imageWithCGImage:imagePick.image.CGImage];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace 
                                          context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation];
NSLog(@"imageOptions %@",imageOptions);
NSArray* features = [detector featuresInImage:image options:imageOptions];

if([features count] > 0)
{
    NSLog(@"Face Found");
}
else
{
    NSLog(@"Face not Found");        
}
}

and this algorithm is not working if I click a snap from landscape mode. Why? Any help would be appreciated.

Thanks in Advance

iYahoo
  • 184
  • 3
  • 16
  • 1
    Does it work for images taken in portrait upside down mode (home button on top). You can try rotating capture image by applying a transform.. – Swapnil Luktuke Jul 23 '12 at 07:16
  • Have a look on it http://stackoverflow.com/questions/10496724/how-to-develop-a-face-recognition-iphone-app/10497002#10497002 it may help you :) – Nikhil Bansal Jul 23 '12 at 07:18

1 Answers1

0

I think the problem is in this line:

NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation];

You are actually telling it to look for portrait orientations only as the number you are passing is 6.

The documentation in the header file says that:

// Options that can be used with -[CIDetector featuresInImage:options:]

/* The value for this key is an integer NSNumber from 1..8 such as that found in kCGImagePropertyOrientation. If present, the detection will be done based on that orientation but the coordinates in the returned features will still be based on those of the image. */

And the options are

enter image description here

It's annoying that featuresInImage:options: is not documented (I'll have to file a bug now that I've seen it)

Abizern
  • 146,289
  • 39
  • 203
  • 257