IOS 6 Face Detection Not Working

2.4k Views Asked by At

I have used the following code to detect the face for IOS 5

CIImage  *cIImage = [CIImage imageWithCGImage:image.CGImage];
            CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];
            NSArray *features = nil;
            features = [detector featuresInImage:cIImage];
            if ([features count] == 0) 
            {
                NSDictionary* imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:6] forKey:CIDetectorImageOrientation];
                features = [detector featuresInImage:cIImage options:imageOptions];
            }

With this code, i am able to detect the face in IOS 5, But recently we have upgraded our Systems to Xcode 4.4 and IOS 6, Now, the face Detection is not working properly,

What changes i need to do for detecting the face in IOS 6.

Anykind of Help is highly Appreciated

2

There are 2 best solutions below

0
On

I hope this helpful for u...

add the CoreImage.framework

-(void)faceDetector

{

// Load the picture for face detection

UIImageView* image = [[UIImageView alloc] initWithImage:

[UIImage imageNamed:@"facedetectionpic.jpg"]];

// Draw the face detection image

[self.window addSubview:image];

// Execute the method used to markFaces in background

[self markFaces:image];

}


-(void)faceDetector

{

// Load the picture for face detection

    UIImageView* image = [[UIImageView alloc] initWithImage:[UIImage 
imageNamed:@"facedetectionpic.jpg"]];


    // Draw the face detection image
    [self.window addSubview:image];

    // Execute the method used to markFaces in background
    [self performSelectorInBackground:@selector(markFaces:) withObject:image];

    // flip image on y-axis to match coordinate system used by core image
    [image setTransform:CGAffineTransformMakeScale(1, -1)];

    // flip the entire window to make everything right side up
    [self.window setTransform:CGAffineTransformMakeScale(1, -1)];


}

and check this two links also

http://maniacdev.com/2011/11/tutorial-easy-face-detection-with-core-image-in-ios-5/

http://i.ndigo.com.br/2012/01/ios-facial-recognition/

0
On

I have noticed that face detection in iOS6 is not as good as in iOS5. Try with a selection of images. You will likely find that it works OK in iOS6 with a lot of the images, but not all of them.

I have been testing the same set of images in: 1. The emulator running iOS6. 2. iPhone 5 (iOS6) 3. iPhone 3GS (iOS5).

The 3GS detects more faces than the other two options.

Here's the code, it works on both, but just not as well on iOS6:

- (void)analyseFaces:(UIImage *)facePicture {
// Create CI image of the face picture
CIImage* image = [CIImage imageWithCGImage:facePicture.CGImage];

// Create face detector with high accuracy
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                          context:nil options:[NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy]];

// Create array of detected faces
NSArray* features = [detector featuresInImage:image];

// Read through the faces and add each face image to facesFound mutable
for(CIFaceFeature* faceFeature in features)
{
    CGSize parentSize = facePicture.size;

    CGRect origRect = faceFeature.bounds;
    CGRect flipRect = origRect;
    flipRect.origin.y = parentSize.height - (origRect.origin.y + origRect.size.height);

    CGImageRef imageRef = CGImageCreateWithImageInRect([facePicture CGImage], flipRect);
    UIImage *faceImage = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);

    if (faceImage)
        [facesFound addObject:faceImage];
} 

}