简体   繁体   English

从ARReferenceImage获取UIImage或CIImage

[英]Getting a UIImage or CIImage from ARReferenceImage

I am using ARKit to do some animation over ARAnchors . 我正在使用ARKitARKit上进行一些动画ARAnchors My images are stored in an AR Resource Group like below. 我的图像存储在如下所示的AR Resource Group中。

在此处输入图片说明

As such they can be accessed like below in order to load them into my session as tracked images. 因此,可以像下面这样访问它们,以便将它们作为跟踪图像加载到我的会话中。 However, I would also like to do some separate operations on these same images and therefore need to access them as either CIImages or UIImages . 但是, 我也想对这些相同的图像进行一些单独的操作 ,因此需要以CIImagesUIImages形式CIImages进行访问。 Right now I have to import these separately into my project because there doesn't seem to be a way to extract the image from an ARReferenceImage . 现在,我不得不将它们分别导入到我的项目中,因为似乎没有办法从ARReferenceImage提取图像。 Is there a way to do this? 有没有办法做到这一点? It is quite convenient to use the AR Resource Group as it displays relevant warnings about potential conflicts as well as less performant markers before compiling. 使用AR Resource Group非常方便,因为它会在编译前显示有关潜在冲突的警告以及性能较低的标记。 I also assume it would take more time to load up the app if I were to convert say my PNG images into CIImages then into ARReferenceImage in my viewDidLoad() or by some similar means. 我也相信它会花费更多的时间来加载应用程序,如果我要转换说我的PNG图像到CIImages然后进入ARReferenceImage在我viewDidLoad()或一些类似手段。

guard let trackedImages = ARReferenceImage.referenceImages(inGroupNamed: "Photos", bundle: Bundle.main) else {
    print("No images available")
    return
}

Creating ARReferenceImage s in Xcode doesn't put the original images into your app's asset catalog, so the original image isn't available at run time. 在Xcode中创建ARReferenceImage不会将原始图像放入应用程序的资产目录中,因此原始图像在运行时不可用。 (Instead, ARKit pre-processes the image into a form that makes recognition more efficient while using less storage.) (相反,ARKit会将图像预处理为一种形式,从而可以在减少存储空间的同时提高识别效率。)

If you want to use an image both for ARKit recognition and for visual display (or other processing), you'll need to include it in your Asset Catalog twice — once as an AR Reference Image, then again as a normal ( UIImage ) asset. 如果您想同时使用图像进行ARKit识别和视觉显示(或其他处理),则需要将其两次包含在资产目录中-一次作为AR参考图像,然后再次作为常规( UIImage )资产。

Alternatively, you could add it to your asset catalog as a normal image, then create an ARReferenceImage from it at run time — that class has an initializer that takes CGImage . 或者,您可以将其作为普通映像添加到资产目录中,然后在运行时从中创建一个ARReferenceImage -该类具有使用CGImage的初始化CGImage (In that case, it might still be useful to use the AR Reference Images area of the asset catalog to preflight your images and make sure they're good for recognition, even if you're not delivering them that way. (在这种情况下,使用资产目录的“ AR参考图像”区域对图像进行预检可能仍然有用,即使您未采用这种方法,也要确保它们能被识别。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM