CIFaceFeature hasSmile is always false

The following is used 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 legacy code on many images. hasSmile

always returns false.

How do I configure my face detection setting for smile detection correctly?

+3


source to share


1 answer


A quick google search on "CIFaceDetector hasSmile" gives this link on Face and Blink Removal on iOS 7

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

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

      



In Swift, it would be something like this:

let options: [NSObject: AnyObject] = 
  [CIDetectorSmile: true, CIDetectorEyeBlink, true]
var features = ciDetector.featuresInImage(ciImage, options: options)

      

+9


source







All Articles