问题
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 ARImageAnchor
s, 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