gpt4 book ai didi

ios - 可以在 iOS 11.3 beta、xCode 9.3 beta、ARKit 1.5 上跟踪同一 ARReferenceImage 的多个条目

转载 作者:可可西里 更新时间:2023-11-01 00:39:19 24 4
gpt4 key购买 nike

在 iOS SDK iOS 11.3 测试版、xCode 9.3 测试版中,ARKit 1.5 为我们提供了 possibility以与我们使用 ARToolKit 或 Vuforia 相同的方式通过相机跟踪引用图像。

问题是,我能否跟踪完全相同的引用图像的条目数,并在每个图像的顶部放置一些形状,就好像它们是单独的项目一样? documentation状态:

When you run a world-tracking AR session and specify ARReferenceImage objects for the session configuration's detectionImages property, ARKit searches for those images in the real-world environment. When the session recognizes an image, it automatically adds to its list of anchors an ARImageAnchor for each detected image.

我能够为我的 ARWorldTrackingConfiguration 提供三个完全相同的图像(但旋转不同),但它只找到第一个命中图像(它们以类似矩阵的 View 打印在一张纸上)。这是否意味着我只能跟踪每个唯一引用图像的首次点击?

如果我们有 anchor 列表,我们可以尝试计算这是否不是同一个精确点,并可能尝试强制它进一步搜索?

我们将不胜感激。

最佳答案

我很确定不可能直接开箱即用地跟踪同一图像的多次出现,因为当检测到图像时,它会被赋予一个 ARImageAnchor 并且这只会发生一次:

If your AR experience adds virtual content to the scene when an image is detected, that action will by default happen only once. To allow the user to experience that content again without restarting your app, call the session’s remove(anchor:) method to remove the corresponding ARImageAnchor: After the anchor is removed, ARKit will add a new anchor the next time it detects the image.

话虽如此,您可以通过使用此内置函数在特定时间段后手动删除图像的 ARImageAnchor 来跟踪图像显示的次数:

func remove(anchor: ARAnchor)

不过,如果您同时在相机的前端有相同的图像,我认为这不会起作用。

撇开所有的事情不谈,希望这个例子能对你有所帮助......

创建两个变量(一个用于存储检测计数,一个用于存储 anchor ):

   var anchors = [ARImageAnchor]()
var countOfDetectedImages = 0

然后:

  func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {

//1. If Out Target Image Has Been Detected Than Get The Corresponding Anchor
guard let currentImageAnchor = anchor as? ARImageAnchor else { return }

//2. Store The ARImageAnchors
anchors.append(currentImageAnchor)

//3. Get The Targets Name
let name = currentImageAnchor.referenceImage.name!

print("Image Name = \(name)")

//4. Increase The Count If The Reference Image Is Called Target
if name == "target"{

countOfDetectedImages += 1

print("\(name) Has Been Detected \(countOfDetectedImages)")

//6. Remove The Anchor
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
self.augmentedRealitySession.remove(anchor: anchor)
}
}

}

对于变量的完全重置:

 /// Removes All The ARImageAnchors & The Detected Count
func removeAllAnchorsAndResetCount(){

countOfDetectedImages = 0
anchors.forEach{ augmentedRealitySession.remove(anchor: $0) }
anchors.removeAll()
}

可能的解决方法:

仅供引用,Apple Documentation 中有一些注释它具有以下初始化方法:

init(CGImage, orientation: CGImagePropertyOrientation, physicalWidth: CGFloat):

从 Core Graphics 图像对象创建新的引用图像。

init(CVPixelBuffer, orientation: CGImagePropertyOrientation, physicalWidth: CGFloat)

从 Core Video 像素缓冲区创建新的引用图像。

所以“也许”,我还没有研究过这个,你也许可以那样处理方向?

关于ios - 可以在 iOS 11.3 beta、xCode 9.3 beta、ARKit 1.5 上跟踪同一 ARReferenceImage 的多个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49069512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com