Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

ios - ARKit Scene with tracking images start jumping

Something strange happened, I just created a simple app. My app was can tracking images and I add a SCNPlane over the image. But when my images get some perspective the SCNPlane starts jumping. Look at the video for a better understanding: https://youtu.be/nDRcGoCq7Oo

So as you see when I detect simple image like "Bruce Wayne" all good but when I'll try to detect "building" it's started jumping. I think the ARKit can't understand how to prepare this image, but I can't understand how to fix that and where I should start.

Here is some code:

...

 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)
    }
    
question from:https://stackoverflow.com/questions/65844481/arkit-scene-with-tracking-images-start-jumping

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The quality from image tracking greatly varies between the quality of the marker itself (e.g. how many "feature points" can be identified), the quality of the surrounding (ever wondered why all Apple ARKit demos are on big wodden, textured tables?) and the quality of the printed marker. Because your image is just shown on your monitor the tracking quality isn't great. Try to print out the image and try again there.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...