使用以下方法检测图像中的面部:
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。
如何配置面部检测以正确检测笑脸?
答案 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)