简体   繁体   English

ARKit 无法识别参考图像

[英]ARKit does not recognize reference images

I'm trying to place a 3D model on top of a recognized image with ARKit and RealityKit - all programmatically.我正在尝试使用 ARKit 和 RealityKit 将 3D 模型放置在已识别图像的顶部 - 全部以编程方式。 Before I start the ARView I'm downloading the model I want to show when the reference image is detected.在我开始 ARView 之前,我正在下载我想在检测到参考图像时显示的模型。

This is my current setup:这是我目前的设置:

override func viewDidLoad() {
    super.viewDidLoad()
    
    arView.session.delegate = self
    
    // Check if the device supports the AR experience
    if (!ARConfiguration.isSupported) {
        TLogger.shared.error_objc("Device does not support Augmented Reality")
        return
    }
    
    guard let qrCodeReferenceImage = UIImage(named: "QRCode") else { return }
    let detectionImages: Set<ARReferenceImage> = convertToReferenceImages([qrCodeReferenceImage])
    
    let configuration = ARWorldTrackingConfiguration()
    configuration.detectionImages = detectionImages
    
    arView.session.run(configuration, options: [.resetTracking, .removeExistingAnchors])
}

I use the ARSessionDelegate to get notified when a new image anchor was added which means the reference image got detected:我使用 ARSessionDelegate 在添加新图像锚点时收到通知,这意味着检测到参考图像:

func session(_ session: ARSession, didAdd anchors: [ARAnchor]) {
    print("Hello")
    for anchor in anchors {
        guard let imageAnchor = anchor as? ARImageAnchor else { return }
        let referenceImage = imageAnchor.referenceImage
        
        addEntity(self.localModelPath!)
    }
}

However, the delegate method never gets called while other delegate functions like func session(ARSession, didUpdate: ARFrame) are getting called so I assume that the session just doesn't detect the image.但是,当其他委托函数如func session(ARSession, didUpdate: ARFrame)被调用时,委托方法永远不会被调用,所以我假设会话只是没有检测到图像。 The image resolution is good and the printed image the big so it should definitely get recognized by the ARSession.图像分辨率很好,打印的图像很大,所以它肯定会被 ARSession 识别。 I also checked that the image has been found before adding it to the configuration.在将其添加到配置之前,我还检查了该图像是否已找到。

Can anyone lead me in the right direction here?任何人都可以在这里引导我朝着正确的方向前进吗?

It looks like you have your configuration set up correctly.看起来您的配置设置正确。 Your delegate-function should be called when the reference image is recognized.当参考图像被识别时,你的委托函数应该被调用。 Could you check if there is any point in your code where the configuration is overwritten?您能检查一下您的代码中是否有任何地方覆盖了配置吗?

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

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