我正在使用ARKit(使用SceneKit)添加虚拟对象(例如球).我通过使用Vision框架并在视觉请求完成处理程序方法中接收其更新位置来跟踪真实世界对象(例如,脚).
let request = VNTrackObjectRequest(detectedObjectObservation: lastObservation, completionHandler: self.handleVisionRequestUpdate)
Run Code Online (Sandbox Code Playgroud)
我想用虚拟替换跟踪的现实世界对象(例如用立方体替换脚)但是我不知道如何将边界框矩形(我们在视觉请求完成中接收)替换为场景套件节点,因为坐标系统是不同的.
以下是视觉请求完成处理程序的代码:
private func handleVisionRequestUpdate(_ request: VNRequest, error: Error?) {
// Dispatch to the main queue because we are touching non-atomic, non-thread safe properties of the view controller
DispatchQueue.main.async {
// make sure we have an actual result
guard let newObservation = request.results?.first as? VNDetectedObjectObservation else { return }
// prepare for next loop
self.lastObservation = newObservation
// check the confidence level before updating the UI
guard newObservation.confidence >= 0.3 else { …Run Code Online (Sandbox Code Playgroud)