【发布时间】:2023-03-12 01:01:01
【问题描述】:
我有一个应用程序,它使用 iOS 13 身体跟踪,使用 ARKit 在人体中实时放置一些标记。
以下代码允许我实时绘制标记并在屏幕上获取它们的坐标。
func session(_ session: ARSession, didUpdate frame: ARFrame) {
if let detectedBody = frame.detectedBody {
guard let interfaceOrientation = arView.window?.windowScene?.interfaceOrientation else { return }
let transform = frame.displayTransform(for: interfaceOrientation, viewportSize: arView.frame.size)
//This array contains only the lower body joints
var arrayOfJoints = [detectedBody.skeleton.jointLandmarks[8],detectedBody.skeleton.jointLandmarks[9],detectedBody.skeleton.jointLandmarks[10],detectedBody.skeleton.jointLandmarks[11],detectedBody.skeleton.jointLandmarks[12],detectedBody.skeleton.jointLandmarks[13],detectedBody.skeleton.jointLandmarks[16]]
//Todo lo de este for estaba en el .forEach
for i in 0...arrayOfJoints.count - 1 {
let normalizedCenter = CGPoint(x: CGFloat(arrayOfJoints[i][0]), y: CGFloat(arrayOfJoints[i][1])).applying(transform)
let center = normalizedCenter.applying(CGAffineTransform.identity.scaledBy(x: arView.frame.width, y: arView.frame.height))
let circleWidth: CGFloat = 10
let circleHeight: CGFloat = 10
let rect = CGRect(origin: CGPoint(x: center.x - circleWidth/2, y: center.y - circleHeight/2), size: CGSize(width: circleWidth, height: circleHeight))
let circleLayer = CAShapeLayer()
circleLayer.fillColor = .init(srgbRed: 255, green: 255, blue: 255, alpha: 1.0)
circleLayer.path = UIBezierPath(ovalIn: rect).cgPath
arView.layer.addSublayer(circleLayer)
}
}
}
但是,我找不到获取真实世界坐标的方法,例如,在深蹲期间以厘米为单位的臀部位移是多少。甚至可以使用 ARKit 将这些点转换为真实世界的坐标吗?
非常感谢
【问题讨论】:
标签: swift arkit motion-detection