【问题标题】:Swift - How to detect one eye blinkSwift - 如何检测一只眼睛眨眼
【发布时间】:2020-04-05 12:31:39
【问题描述】:

我使用 CoreImage 来检测眨眼,它工作正常,除非我尝试只检测一只眼睛。关于如何使用 CoreImage 检测眼神接触调情的任何想法?

if let faceImage = CIImage(image: target) {  
    let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
    let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy)
    let faces = faceDetector?.features(in: faceImage, options: [CIDetectorSmile:true, CIDetectorEyeBlink: true])

     if !faces!.isEmpty {
         for face in faces as! [CIFaceFeature] {
             let leftEyeClosed = face.leftEyeClosed
             let rightEyeClosed = face.rightEyeClosed
             let blinking = face.rightEyeClosed && face.leftEyeClosed
             let isSmiling = face.hasSmile

             print("isSmiling \(isSmiling)")
             print("blinking \(blinking)")
             print("rightEyeClosed \(rightEyeClosed)")
             print("leftEyeClosed \(leftEyeClosed)\n\n")
         }
     } else {
         print("No faces found")
     }
}

UPDATE 属性 hasLeftEyePosition 和 hasRightEyePosition 始终为真。

双眼紧闭

isSmiling false
blinking true
rightEyeClosed true
leftEyeClosed true

双眼睁开

isSmiling false
blinking false
rightEyeClosed false
leftEyeClosed false

左眼闭上

isSmiling false
blinking false
rightEyeClosed false
leftEyeClosed false

右眼闭上

isSmiling false
blinking false
rightEyeClosed false
leftEyeClosed false

【问题讨论】:

  • prints 的(预期和实际)输出是什么?什么不工作?
  • 我已经更新了问题。不幸的是,通过使用 CoreImage,我无法捕捉到“调情”。

标签: ios swift swift4 core-image


【解决方案1】:

要启用或禁用检测器的面部跟踪,我必须设置 CIDetectorTracking 变量。它可以很好地捕捉眨眼,但由于实时视频的性能较慢,我决定使用 ARKit 来实现它。

let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh, CIDetectorTracking: true] as [String : Any]

https://developer.apple.com/documentation/coreimage/cidetectortracking

【讨论】:

  • 对我来说,启用此选项确实可以为左右眼提供单独的结果,但是当能够检测到双眼睁开时,它变得更加不稳定。
猜你喜欢
  • 2015-11-27
  • 1970-01-01
  • 2015-12-11
  • 2012-11-01
  • 2023-04-02
  • 1970-01-01
  • 2011-10-28
  • 2012-03-20
  • 2012-08-27
相关资源
最近更新 更多