0

I'm using Core Image for face detection like this:

 CIImage* image = [CIImage imageWithCGImage:aImage.CGImage];

//create Facedetector
NSDictionary  *opts = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh
                                                  forKey:CIDetectorAccuracy];
CIDetector* detector = [CIDetector detectorOfType:CIDetectorTypeFace
                                          context:nil
                                          options:opts];

//Pull out the features of the face and loop through them
NSArray* features = [detector featuresInImage:image];

But I found that when I use a picture with completely face, it could detect the face correctly, but when I use a incompletely face, it failed , just as the following snapshot: enter image description here

What's wrong with my code, does it that the CIDetector only works well with the completely face?

[update] here is my code, I could only detect the left

HamGuy
  • 916
  • 1
  • 7
  • 18
  • Use featuresInImage:options: instead of featuresInImage: with orientation information as suggested here https://developer.apple.com/library/prerelease/ios/documentation/CoreImage/Reference/CIDetector_Ref/index.html#//apple_ref/doc/constant_group/Detector_Types – Jageen Jan 30 '15 at 04:07
  • Do you mean that using the example image you can't detect a face? How many faces did you detect using the image? – gabbler Jan 30 '15 at 04:22
  • @gabbler Actually there was only one face in the picture, and the shortcut has two pictures :) – HamGuy Jan 30 '15 at 05:37
  • So, the image in your post contains two faces, but only one face is detected? – gabbler Jan 30 '15 at 05:50
  • @gabbler Yeah, only the left image was detected – HamGuy Jan 30 '15 at 06:22
  • That is not true, I detected 2 faces. – gabbler Jan 30 '15 at 06:23
  • @gabbler Really, I could only detect the left one. And I just update my question with the code link. – HamGuy Jan 30 '15 at 06:47
  • @Jageen I tried as your guide, `[detector featuresInImage:image options:@{CIDetectorImageOrientation:@(1)}];`and it could not be detected either. – HamGuy Jan 30 '15 at 09:55

1 Answers1

0

Sometimes it can't be detected it if it is not a full face, I don't think you can do anything about it.

But you can add a white border to the image and then it can be detected, see the picture below, or you can dive into openCV and see if it can be detected by openCV library. The image in your post has two faces, if you download it and try it you will find out, mostly because it has white border around the right face which is the same color as the background color.

face detection result

What I did was add the imageView as subview of a container view, which frame is slightly bigger than frame of imageView. Then I did a snapshot of the container view. The picture reflect the detection result of the snapshot image.

gabbler
  • 13,626
  • 4
  • 32
  • 44