我正在尝试为 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/