我正在尝试使用CoreImage CIFeature来检测面部情绪,因为这些都是原生API。我已经创建了一个样例视图控制器项目,并更新了相关代码。当我启动这个iOS应用程序时,它打开了摄像头。当我抬头看相机并显示微笑情绪时,下面的示例代码检测正常。我还需要找到其他情绪,比如惊讶、悲伤和愤怒的情绪。我知道CoreImage CIFeature没有针对这些其他情绪的直接API。但是,是否可以尝试操作可用的API(如hasSmile、leftEyeClosed、rightEyeClosed等)?通过iOS程序检测其他情绪,如惊讶、悲伤和愤怒?
有没有人会遇到使用这个API,场景和解决这个问题的人,请建议并分享你的想法。
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
let opaqueBuffer = Unmanaged<CVImageBuffer>.passUnretained(imageBuffer!).toOpaque()
let pixelBuffer = Unmanaged<CVPixelBuffer>.fromOpaque(opaqueBuffer).takeUnretainedValue()
let sourceImage = CIImage(cvPixelBuffer: pixelBuffer, options: nil)
options = [CIDetectorSmile : true as AnyObject, CIDetectorEyeBlink: true as AnyObject, CIDetectorImageOrientation : 6 as AnyObject]
let features = self.faceDetector!.features(in: sourceImage, options: options)
for feature in features as! [CIFaceFeature] {
if (feature.hasSmile) {
DispatchQueue.main.async {
self.updateSmileEmotion()
}
}
else {
DispatchQueue.main.async {
self.resetEmotionLabel()
}
}
}
func updateSmileEmotion () {
self.emtionLabel.text = " "
self.emtionLabel.text = "HAPPY"
}
func resetEmotionLabel () {
self.emtionLabel.text = " "
}发布于 2016-11-17 08:20:31
有各种各样的库可以对图像进行情感分析,其中大多数依赖于机器学习。仅仅通过查看CIFeature给你提供了什么,你就不太可能得到同样的结果,因为它非常有限,即使与其他面部识别库相比也是如此。请参阅Google Cloud Vison、IBM Watson Cloud iOS SDK、Microsoft Cognitive Services
https://stackoverflow.com/questions/40642919
复制相似问题