【问题标题】:ARKit Scene with tracking images start jumping带有跟踪图像的 ARKit 场景开始跳跃
【发布时间】:2021-04-26 21:07:41
【问题描述】:

发生了一些奇怪的事情,我刚刚创建了一个简单的应用程序。我的应用可以跟踪图像,我在图像上添加了 SCNPlane。但是当我的图像得到一些透视时,SCNPlane 开始跳跃。看视频加深理解:https://youtu.be/nDRcGoCq7Oo

正如你所见,当我检测到像 “Bruce Wayne” 这样的简单图像时,一切都很好,但是当我尝试检测“building”时,它开始跳跃。 我认为 ARKit 无法理解如何准备此图像,但我无法理解如何解决该问题以及我应该从哪里开始。

这里有一些代码:

...

 override func viewDidLoad() {
        super.viewDidLoad()
        initScene()
    }
    
    func initScene(){
        sceneView.delegate = self
        sceneView.showsStatistics = true

        // Create a new scene
        let scene = SCNScene(named: "art.scnassets/videoScene.scn")!
        self.sceneView.autoenablesDefaultLighting = false

        // Set the scene to the view
        sceneView.scene = scene
    }

...

  override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        openedDetailScreen = false
        let configuration = ARImageTrackingConfiguration()
        configuration.trackingImages = arImageReference
        configuration.maximumNumberOfTrackedImages = 2
        
        self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints, ARSCNDebugOptions.showWorldOrigin]
        self.configuration = configuration
        sceneView.session.run(configuration)
        
        initRecognition()
        
    }

...

  func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor){
        
        guard anchor is ARImageAnchor else { return }
        
        guard let currentReferenceImageName = ((anchor as? ARImageAnchor)?.referenceImage) else {
            return
        }
        print("size of tracked images \(currentReferenceImageName.name)")
        
        addVideoScene(withImage: currentReferenceImageName, didAdd: node)
    }

...

  private func addVideoScene(withImage referenceImage: ARReferenceImage,didAdd node: SCNNode){
        videoNode = SKVideoNode(avPlayer: videoPlayer)
        let videoScene = SKScene(size: CGSize(width: 480, height: 360))
        // center our video to the size of our video scene
        videoNode.position = CGPoint(x: videoScene.size.width / 2, y: videoScene.size.height / 2)
        // invert our video so it does not look upside down
        videoNode.yScale = -1.0
        videoScene.addChild(videoNode)
        // create a plan that has the same real world height and width as our detected image
        let plane = SCNPlane(width: referenceImage.physicalSize.width, height: referenceImage.physicalSize.height)
        // set the first materials content to be our video scene
        plane.firstMaterial?.diffuse.contents = videoScene
        // create a node out of the plane
        let planeNode = SCNNode(geometry: plane)
        // since the created node will be vertical, rotate it along the x axis to have it be horizontal or parallel to our detected image
        planeNode.eulerAngles.x = -Float.pi / 2
        node.addChildNode(planeNode)
    }
    

【问题讨论】:

    标签: ios swift arkit


    【解决方案1】:

    图像跟踪的质量在标记本身的质量(例如,可以识别多少“特征点”)和周围环境的质量(曾经想知道为什么所有 Apple ARKit 演示都在大木纹理的桌子上)之间存在很大差异?) 和印刷标记的质量。因为您的图像只是显示在您的显示器上,所以跟踪质量不是很好。尝试打印出图像并在那里重试。

    【讨论】:

    • 给我一些时间测试)我会回来
    • 同样的结果,我在 iPhone 6s 和 XS Max 上进行测试。也许我们可以在图像上设置一些默认参数而不用跟踪透视。更新结果:youtu.be/H-h2BwbisdQ
    猜你喜欢
    • 2019-01-26
    • 2017-11-08
    • 2018-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2018-08-17
    相关资源
    最近更新 更多