【问题标题】:Possibility to track multiple entries of same ARReferenceImage on iOS 11.3 beta, xCode 9.3 beta, ARKit 1.5可以在 iOS 11.3 beta、xCode 9.3 beta、ARKit 1.5 上跟踪相同 ARReferenceImage 的多个条目
【发布时间】:2018-08-10 16:35:19
【问题描述】:

在 iOS SDK iOS 11.3 beta、xCode 9.3 beta、 ARKit 1.5 为我们提供了 possibility 以通过相机跟踪参考图像,就像我们使用 ARToolKit 或 Vuforia 一样。

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

当您运行世界跟踪 AR 会话并为会话配置的 detectionImages 属性指定 ARReferenceImage 对象时,ARKit 会在真实环境中搜索这些图像。当会话识别图像时,它会自动为每个检测到的图像添加一个 ARImageAnchor 到其锚点列表中。

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

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

任何帮助将不胜感激。

【问题讨论】:

    标签: ios swift xcode arkit beta


    【解决方案1】:

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

    如果您的 AR 体验在检测到图像时将虚拟内容添加到场景中,则默认情况下该操作只会发生一次。要让用户在不重新启动应用的情况下再次体验该内容,请调用会话的 remove(anchor:) 方法来删​​除相应的 ARImageAnchor: 移除anchor后,ARKit下次会添加新anchor 它检测图像。

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

    func remove(anchor: ARAnchor)
    

    但是,如果您同时在相机的霜状体中拥有相同的图像,我认为这不会起作用。

    抛开一切,希望这个例子可以帮助你...

    创建两个变量(一个存储检测计数,一个存储锚点):

       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, 方向: CGImagePropertyOrientation, 物理宽度:CGFloat)

    从核心视频像素缓冲区创建一个新的参考图像。

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

    【讨论】:

    • 感谢您的回复!我会处理您提供的信息。需要尝试至少几种可能的解决方案并找到最合适的解决方案。现在,您已经证实了我的想法,即开箱即用是不可能的 :) 干杯。
    猜你喜欢
    • 2018-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2019-12-15
    • 2019-11-30
    • 1970-01-01
    相关资源
    最近更新 更多