是否可以使用ARKit识别虚拟图像而不是真实图像? (iOS 12)

时间:2019-01-07 11:19:04

标签: ios swift scenekit arkit

我做了很少的AR图像跟踪应用程序和AR World跟踪应用程序。

AR图像跟踪可用于识别从相机捕获的物理地图上的图像。

有什么方法可以使AR Image Tracking识别基本上是SCNPlane材料的虚拟“图像”?

如果有人可以给我一些指导或建议,我们将不胜感激。

注意:,对于该项目,我在ARWorldTrackingConfiguration上使用检测图像)

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为可能是的,可以通过将内容图像(要在地图中检测到的图像)添加到Assets.xcassets中来实现。然后使用此代码检测虚拟图像,如下所示:

///将您的图片名称放入(withName:“ namehere”)

 lazy var mapNode: SCNNode = {
       let node = scene.rootNode.childNode(withName: "map", recursively: false)
        return node
    }()

// Now When detecting Images 


extension ViewController: ARSCNViewDelegate {

        func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
            DispatchQueue.main.async {
                guard let imageAnchor = anchor as? ARImageAnchor,
                    let imageName = imageAnchor.referenceImage.name else { return }

                // TODO: Comment out code
                //            let planeNode = self.getPlaneNode(withReferenceImage: imageAnchor.referenceImage)
                //            planeNode.opacity = 0.0
                //            planeNode.eulerAngles.x = -.pi / 2
                //            planeNode.runAction(self.fadeAction)
                //            node.addChildNode(planeNode)

                // TODO: Overlay 3D Object
                let overlayNode = self.getNode(withImageName: imageName)
                overlayNode.opacity = 0
                overlayNode.position.y = 0.2
                overlayNode.runAction(self.fadeAndSpinAction)
                node.addChildNode(overlayNode)

                self.label.text = "Image detected: \"\(imageName)\""
            }
        }

        func getPlaneNode(withReferenceImage image: ARReferenceImage) -> SCNNode {
            let plane = SCNPlane(width: image.physicalSize.width,
                                 height: image.physicalSize.height)
            let node = SCNNode(geometry: plane)
            return node
        }

        func getNode(withImageName name: String) -> SCNNode {
            var node = SCNNode()
            switch name {
            case "map":
                node = mapNode

            default:
                break
            }
            return node
        }

    }