使用以下方法检测图像中的人脸:

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。

我必须如何配置人脸检测才能正确检测微笑?

最佳答案

对“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)

关于ios - CIFaceFeature hasSmile 总是假的,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29756283/

10-14 23:24