CIFaceFeature hasSmile始终为false

时间:2015-04-20 19:05:24

标签: ios objective-c swift

使用以下方法检测图像中的面部:

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)")
}

我在许多图片上运行了以前的代码。 hasSmile始终返回false。

如何配置面部检测以正确检测笑脸?

1 个答案:

答案 0 :(得分:10)

快速谷歌搜索“CIFaceDetector hasSmile”会在Face Smiling and Blinking detection on iOS 7上生成此链接

看起来您需要使用不同形式的ciDetector.featuresInImage调用。 Objective-C中的代码如下所示:

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

在Swift中会出现类似::

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