ios - 提高 VNDetectHumanBodyPoseRequest 的 body 跟踪性能

标签 ios swift avfoundation vision avkit

我正在尝试为 VNDetectHumanBodyPoseRequest 提高使用 body 跟踪绘制骨架的性能即使距离超过 5 米,并且配备稳定的 iPhone XS 摄像头。
跟踪对我 body 右下肢的信心很低,明显的滞后并且有抖动。我无法复制今年 WWDC 中展示的性能 demo video .
这是相关代码,改编自 Apple's sample code :

class Predictor {
  func extractPoses(_ sampleBuffer: CMSampleBuffer) throws -> [VNRecognizedPointsObservation] {
    let requestHandler = VNImageRequestHandler(cmSampleBuffer: sampleBuffer, orientation: .down)
    
    let request = VNDetectHumanBodyPoseRequest()
    
    do {
      // Perform the body pose-detection request.
      try requestHandler.perform([request])
    } catch {
      print("Unable to perform the request: \(error).\n")
    }
    
    return (request.results as? [VNRecognizedPointsObservation]) ?? [VNRecognizedPointsObservation]()
  }
}
我已经捕获了视频数据并在此处处理示例缓冲区:
class CameraViewController: AVCaptureVideoDataOutputSampleBufferDelegate {

  func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    let observations = try? predictor.extractPoses(sampleBuffer)
    observations?.forEach { processObservation($0) }
  }

  func processObservation(_ observation: VNRecognizedPointsObservation) {
    
    // Retrieve all torso points.
    guard let recognizedPoints =
            try? observation.recognizedPoints(forGroupKey: .all) else {
      return
    }
    
    let storedPoints = Dictionary(uniqueKeysWithValues: recognizedPoints.compactMap { (key, point) -> (String, CGPoint)? in
      return (key.rawValue, point.location)
    })
    
    DispatchQueue.main.sync {
      let mappedPoints = Dictionary(uniqueKeysWithValues: recognizedPoints.compactMap { (key, point) -> (String, CGPoint)? in
        guard point.confidence > 0.1 else { return nil }
        let norm = VNImagePointForNormalizedPoint(point.location,
                                                  Int(drawingView.bounds.width),
                                                  Int(drawingView.bounds.height))
        return (key.rawValue, norm)
      })
      
      let time = 1000 * observation.timeRange.start.seconds
      
      
      // Draw the points onscreen.
      DispatchQueue.main.async {
        self.drawingView.draw(points: mappedPoints)
      }
    }
  }
}
drawingView.draw函数用于自定义 UIView在相机 View 的顶部,并使用 CALayer 绘制点子层。 AVCaptureSession代码与示例代码完全相同here .
我尝试使用 VNDetectHumanBodyPoseRequest(completionHandler:)变体,但这对我的表现没有影响。我可以尝试使用移动平均滤波器进行平滑......但仍然存在非常不准确的异常值预测问题。
我错过了什么?

最佳答案

我认为这是 iOS 14 beta v1-v3 上的一个错误。升级到 v4 和更高版本的 beta 版本后,跟踪要好得多。 API 也变得更加清晰,带有最新的 beta 更新的细粒度类型名称。
请注意,我没有从 Apple 那里得到有关此错误的官方答复,但此问题可能会在官方 iOS 14 版本中完全消失。

关于ios - 提高 VNDetectHumanBodyPoseRequest 的 body 跟踪性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62886107/

相关文章:

ios - physicsBody = SKPhysicsBody(edgeLoopF​​romRect : view. 帧)

ios - 尝试将视频与 AVMutableComposition : "objects cannot be nil". 合并时出现异常错误..但它们似乎并不为零?

ios - AVAssetExportSession 因特定视频的未知错误 -12780 而失败

ios - 如何用 isVideoMirrored 替换 isMirrored

ios - 声音在我的模拟器上有效,但在我的设备上无效... SWIFT

ios - UITabBarController 内 UINavigationController 的 UINavigationBar 中缺少按钮的插图

ios - swift ios 10 异步或在后台执行代码

ios - 将数据从 UICollectionView 快速/传递到 DetailView/自定义按钮

ios - React Native 如何使用 expo 和 firebase 设置推送通知

swift - 如何在 Xcode 11/Swift 5.1 中使用 Swift Package Manager 创建动态框架(像 Carthage 那样)?