如何在实时跟踪中将3d对象包裹在检测到的对象周围

时间:2019-06-19 09:45:31

标签: swift arkit image-recognition coreml vision

我已经将脚的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()
    }

但是我在x,y的高度和宽度方面在objectBounds变量中仅获得2d坐标... 我需要知道ARScene空间中的3d坐标才能放置我的3d对象... 当我输入相同的x和y时,命中测试也不会返回任何坐标 我认为Arkit世界坐标和普通电话世界坐标之间存在某种关系

提前感谢

0 个答案:

没有答案