2016-11-16 64 views
0

我試圖使用CoreImage CIFeature來檢測臉部情緒,因爲這些是本機API。我創建了一個示例視圖控制器項目並更新了相關的代碼。當我啓動這個iOS應用程序時,它會打開相機。當我查看相機並顯示微笑情緒時,下面的示例代碼會檢測到正常。 我還需要找到其他情感,如驚喜,悲傷和憤怒的情緒。我瞭解CoreImage CIFeature沒有針對這些其他情緒的直接API。但是,是否有可能通過iOS程序嘗試操縱可用的API(如hasSmile,leftEyeClosed,rightEyeClosed等)來檢測其他情緒,如驚喜,悲傷和憤怒?CoreImage用於檢測臉部情緒的CIFeature

任何人都可以使用這個APIs,場景和解決這個問題,請建議和分享你的想法。

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

回答

0

有許多庫可以對圖像進行情感分析,其中大部分依賴於機器學習。通過查看CIFeature提供給您的結果,您很可能得不到相同的結果,因爲即使與其他面部識別庫相比,它的相當有限。請參閱Google Cloud VisonIBM Watson Cloud iOS SDKMicrosoft Cognitive Services

+0

感謝您的建議。我在看如果有任何完全開源的可用,可以閱讀和修改更多。 – Stella