我试图在运行时将UIImage保存到AR资源组中,以便在之后检测它。您可以使用referenceImagesInGroupNamed:bundle读取此组:但没有关于如何编写它的说明。
我正在尝试以下方法:
//step 1: list all reference images
print("BEFORE = ", ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: nil) ?? "None")
//step 2: take snapshot
let snapshot = self.viewController?.sceneView.snapshot()
//optional crops and image processing here
//step 3: add shapshot to bundle
let referenceImage = ARReferenceImage(snapshot.cgImage, orientation: CGImagePropertyOrientation.up, physicalWidth: someComputedPhysicalWidth)
// ??
//step 4: list all reference images and ensure new one is added
print("AFTER = ", ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: nil) ?? "None")
//step 5: relaunch session if intempted to redirect it now
sceneView.session.pause()
configuration.detectionImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: nil)!
sceneView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
关闭应用后,会保存组中存储的内容吗?我可以删除其中的内容吗?如果写访问是不可能的,我想我可以在某处保存创建的referenceImage参数并在需要时重建referenceImage?