4

我已经为脚创建了 ML 模型作为 VNRecognizedObjectObservation 现在我能够成功地在实时跟踪中检测脚,问题是我无法在脚上包裹或放置 3d 对象,因为我需要 3 个坐标来放置 AR 内容。

在视觉框架检测到我的脚后,我使用下面的代码来获取边界框

func drawVisionRequestResults(_ results: [Any]) {
        CATransaction.begin()
        CATransaction.setValue(kCFBooleanTrue, forKey: kCATransactionDisableActions)
        detectionOverlay.sublayers = nil // remove all the old recognized objects

        let obs = results.first
        let final = obs

        for observation in results where observation is VNRecognizedObjectObservation {
            guard let objectObservation = observation as? VNRecognizedObjectObservation else {
                continue
            }
            // Select only the label with the highest confidence.
            let topLabelObservation = objectObservation.labels[0]
            let objectBounds = VNImageRectForNormalizedRect(objectObservation.boundingBox, Int(bufferSize.width), Int(bufferSize.height))

            let shapeLayer = self.createRoundedRectLayerWithBounds(objectBounds)

            let textLayer = self.createTextSubLayerInBounds(objectBounds,
                                                            identifier: topLabelObservation.identifier,
                                                            confidence: topLabelObservation.confidence)
            shapeLayer.addSublayer(textLayer)
            detectionOverlay.addSublayer(shapeLayer)
            //   addModel(objectBounds)
            translateCoordinate(objectBounds)
        }
        self.updateLayerGeometry()
        CATransaction.commit()
    }

但是我在 objectBounds 变量中仅获得了 x 、 y 高度和宽度方面的 2d 坐标……我需要知道 ARScene 空间中的 3d 坐标才能放置我的 3d 对象……当我输入相同时,命中测试也没有返回坐标x 和 yi 认为 Arkit 世界坐标和普通手机世界坐标有一些关系

提前致谢

4

0 回答 0