ARKit : select what `ARImageAnchor` to track

ε祈祈猫儿з 提交于 2021-01-28 14:09:46

问题


I found out empirically that ARKit does not track more than 4 Image Anchors at the same time; setting maximumNumberOfTrackedImages to a number higher than 4 is ignored :
With a dozen images markers in the frustum of the camera, ARKit detects them all and returns the corresponding ARImageAnchors, however only 4 of them will have isTracked == true.
I could not find any reference about this limitation in the Apple documentation, however it was mentioned in this medium post :

[...] for now you can enable tracking of up to 2 images, but the number will surely grow in future releases.

I would like to choose which anchors are tracked, so I can track precisely the anchors in the center of the screen in priority.

I tried to remove the anchors I don't want to be tracked right now, hoping ARKit would track the others :

func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {

    guard let anchors = sceneView.session.currentFrame?.anchors.compactMap({ $0 as? ARImageAnchor }), anchors.count > 0 else {
        return
    }

    let sortedAnchors = anchors.sorted { distanceToScreenCenter($0, renderer) < distanceToScreenCenter($1, renderer) }

    sortedAnchors.dropFirst(4).filter({ $0.isTracked }).forEach({
        self.sceneView.session.remove(anchor: $0)
    })

But no luck, the removed anchors are added and tracked again instantly.

来源:https://stackoverflow.com/questions/55454599/arkit-select-what-arimageanchor-to-track

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!