- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
目前,我正在使用下面的代码从 Assets.xcassets 的“AR Resources”加载 ARReferenceImage,
guard let trackingImages = ARReferenceImage.referenceImages(inGroupNamed: "AR Resources", bundle: nil) else {
print("Missing expected asset catalog resources.")
return
}
configuration.trackingImages = trackingImages
现在,我正在从服务器下载图像到 iOS 应用程序文档目录中名为“Images”的自定义文件夹。
如何将这些图像用作“跟踪图像”?
最佳答案
为了加载自定义ARReference
来自指定位置而非默认位置的图像 ARAssets Folder
您需要使用以下方法创建它们:
init(CGImage, orientation: CGImagePropertyOrientation, physicalWidth: CGFloat)
在此示例中,我使用 ARWorldTrackingConfiguration
但如果使用 ARImageTrackingConfiguration
的原则是一样的。
假设您将所有下载的图像存储到 [UIImage] 数组中,例如:
let imagesFromServer: [UIImage] = [UIImage(named: "gitHubIcon")!, UIImage(named: "stackOverflowIcon")!]
然后你可以把这些变成ARReferenceImages
使用这样的东西:
/// Converts An Array Of [UIImage] Into A Set Of ARReferenceImages
///
/// - Parameter images: [UIImage])
/// - Returns: Set<ARReferenceImage>
func loadedImagesFromDirectoryContents(_ images: [UIImage]) -> Set<ARReferenceImage>{
var index = 0
var customReferenceSet = Set<ARReferenceImage>()
images.forEach { (downloadedImage) in
//1. Convert The UIImage To A CGImage
guard let cgImage = downloadedImage.cgImage else { return }
//2. Get The Width Of The Image
let imageWidth = CGFloat(cgImage.width)
//3. Create A Custom AR Reference Image With A Unique Name
let customARReferenceImage = ARReferenceImage(cgImage, orientation: CGImagePropertyOrientation.up, physicalWidth: imageWidth)
customARReferenceImage.name = "MyCustomARImage\(index)"
//4. Insert The Reference Image Into Our Set
customReferenceSet.insert(customARReferenceImage)
print("ARReference Image == \(customARReferenceImage)")
index += 1
}
//5. Return The Set
return customReferenceSet
}
记住 ARWorldTrackingConfiguration
需要 Set<ARReferenceImage>
.
然后您可以初始化您的自定义 configurations detectionImages
像这样:
let detectionImages = loadedImagesFromDirectoryContents(imagesFromServer)
configuration.detectionImages = detectionImages
augmentedRealitySession.run(configuration, options: [.resetTracking, .removeExistingAnchors])
希望它能为您指明正确的方向...
关于ios - 如何从文档目录加载 ARReferenceImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51998613/
我正在从数据库下载图像并想将它们用作 ARReferenceImage,而不是手动将它们添加到 Xcode Assets 文件夹。 代码 let image = #imageLiteral(r
目前,我正在使用下面的代码从 Assets.xcassets 的“AR Resources”加载 ARReferenceImage, guard let trackingImages = ARRef
我正在开发一个应用程序,其中数据库中有一组ARReferenceImages,供用户下载和使用。这些 ARReferenceImages 由用户创建。 我已经对用户创建的 ARReferenceIma
我想检查 ARReferenceImage在相机的视野中不再可见。目前我可以检查图像的节点是否在相机的 View 中,但是当 ARReferenceImage 时,该节点在相机的 View 中仍然可见
我正在使用 ARKit 在 ARAnchors 上做一些动画。我的图像存储在如下所示的 AR 资源组中。 因此,可以像下面那样访问它们,以便将它们作为跟踪图像加载到我的 session 中。但是,我还
复制: Xcode 9.3 测试版 iOS 11.3 测试版 2 按照文档 here 将 ARReferenceImages 添加到 Assets.xcassets 编译 结果:错误:运行 actoo
在 iOS SDK iOS 11.3 测试版、xCode 9.3 测试版中,ARKit 1.5 为我们提供了 possibility以与我们使用 ARToolKit 或 Vuforia 相同的方式通过
我是一名优秀的程序员,十分优秀!