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

标签 ios swift xcode arkit beta

在 iOS SDK iOS 11.3 beta、xCode 9.3 beta 中, 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 方法用于:

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

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

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

从核心视频像素缓冲区创建新的引用图像。

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

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

相关文章:

浏览器上的 iPhone Youtube 视频

ios - 播放列表(嵌入式)在 iOS 上损坏

ios - 为 UIControlStateHighlighted 设置 UIImage

ios - swift3 中的数据到 Int/String

ios - ARKit : Show object with actual size

ios - 引用 iOS 应用程序的 Xcode 项目中的目录

ios - 如何快速计算两个日期之间的时间(分钟)?

objective-c - 将字符串从 Swift 传递到 Objective C 时出现问题

ios - 如何在 Xcode 中制作跟随手指位置的左/右转场

xcode - 我应该在版本控制中存储 Xcode 项目的哪些文件?