【发布时间】:2020-11-03 06:05:54
【问题描述】:
我正在尝试通过VNDetectHumanBodyPoseRequest 的身体跟踪来提高绘制骨骼的性能,即使在 5 米之外,并且使用稳定的 iPhone XS 摄像头。
跟踪对我身体右下肢的置信度低,滞后明显,有抖动。我无法复制今年 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,并使用CALayer 子层绘制点。 AVCaptureSession 代码与示例代码here 完全相同。
我尝试使用VNDetectHumanBodyPoseRequest(completionHandler:) 变体,但这对我的性能没有影响。不过,我可以尝试使用移动平均滤波器进行平滑处理。但异常值预测仍然存在问题,非常不准确。
我错过了什么?
【问题讨论】:
-
看起来你无法解决它?有更新吗?
-
您好,我遇到了类似的问题,对此我很感兴趣。您找到可以分享的解决方案了吗?谢谢
标签: ios swift avfoundation vision avkit