Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CIFaceFeature hasSmile is always false

Using the following to detect faces in images:

var ciImage  = CIImage(CGImage:imageView.image!.CGImage)
var ciDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil,
  options: [
    CIDetectorAccuracy: CIDetectorAccuracyHigh,
    CIDetectorSmile: true,
    CIDetectorEyeBlink: true
  ])

var features = ciDetector.featuresInImage(ciImage)

for feature:CIFaceFeature in (features as! [CIFaceFeature]) {
   println("has smile: \(feature.hasSmile)")
}

I ran the former code on many images. hasSmile always returns false.

How do I have to configure face detection to detect smiles correctly?


1 Answers

A quick google search on "CIFaceDetector hasSmile" yields this link on Face Smiling and Blinking detection on iOS 7

It looks like you need to use a different form of the ciDetector.featuresInImage call. The code in Objective-C looks like this:

NSDictionary *options = @{ CIDetectorSmile: @(YES), CIDetectorEyeBlink: @(YES),};
NSArray *features = [detector featuresInImage:image options:options];

In Swift that would be something like this::

let options: [NSObject: AnyObject] = 
  [CIDetectorSmile: true, CIDetectorEyeBlink, true]
var features = ciDetector.featuresInImage(ciImage, options: options)
like image 175
Duncan C Avatar answered Oct 26 '25 19:10

Duncan C