Error loading ReferenceImage

Currently, I try to test the ImageTrackingProvider with the Apple Vision Pro. I started with some basic code:

import RealityKit
import ARKit

@MainActor class ARKitViewModel: ObservableObject{
    private let session = ARKitSession()
    private let imageTracking = ImageTrackingProvider(referenceImages: ReferenceImage.loadReferenceImages(inGroupNamed: "AR"))
    
    func runSession() async {
        do{
            try await session.run([imageTracking])
        }
        catch{
            print(error)
        }
    }
    
    func processUpdates() async {
        for await _ in imageTracking.anchorUpdates{
            print("test")
        }
    }
}

I only have one picture in the AR folder. I added the size an I have no error messages in the AR folder.

As I am trying to run the application with the vision Pro, I receive following error:

ar_image_tracking_provider_t <0x28398f1e0>: Failed to load reference image <ARReferenceImage: 0x28368f120 name="IMG_1640" physicalSize=(1.350, 2.149)> with error: Failed to add reference image.

It finds the image, but there seems to be a problem with the loading. I tried the jpeg and the png format.

I do not understand why it fails to load the ReferenceImage.

I use Xcode Version 15.3 beta 3

Replies

There is a known issue in visionOS 1.0 where this error message is displayed if reference images are loaded before entering an immersive space. Could it be that ARKitViewModel, and thus the reference image, is initialized before entering the immersive space?

Note though that this error message is incorrect - as soon as you enter the immersive space, the reference image should be loaded and image tracking should work. Please give it a try!

  • struct ImmersiveView: View {
        @StateObject var arKitVM = ARKitViewModel()
        var body: some View {
            RealityView { content in
                
            }
            .task {
                await arKitVM.runSession()
            }
            .task {
                await arKitVM.processUpdates()
            }
        }
    }
    

    The ARKitViewModel is initialized when entering the immersive space. I receive the error message during runSession(). In this method, I run the ARKitSession with the data provider.

  • It seems that my answer was deleted or not accepted. I checked it and it is not initialized before entering the immersive space. I also tried some recommendations from Stackoverflow but nothing helped.

Add a Comment

Have you tested though whether you receive an image anchor when you point the Vision Pro at a print-out of the reference image file (in a well lit environment)? As mentioned, the error message is incorrect and can be ignored in visionOS 1.0.

  • Thanks, it seems to work. I receive anchor updates with the needed information.

Add a Comment