Adding image to ARImageDetectionManager not working, array is 0

Include the following details (edit as applicable):

  • Issue category: Semantic Segmentation
  • Device type & OS version: iOS
  • Host machine & OS version: Mac
  • Issue Environment : Unity Mock
  • Xcode version:13.4.1
  • ARDK version: 2.0.0
  • Unity version: 2021.3.1f1

Description of the issue:

I’m trying to run this code, the reference to the ArImageDetectionManager is fine I think, get no errors, with Sync or Async methods:

public void AddImageToSession(Texture2D tex)
    {
        var _physicalImageWidth = 1.0f;
        byte[] rawByteBufferAsync = tex.GetRawTextureData();
        IARReferenceImage _yetiImage =
            ARReferenceImageFactory.Create
            (
                "yeti",
                rawByteBufferAsync,
                rawByteBufferAsync.Length,
                _physicalImageWidth
            );
        _arImageDetectionManager.AddImage(_yetiImage);
    }

Once it’s run, the array inside the unity Editor stays at 0, when I’d expect to see the image I’d passed being inside.

The image I’m trying to pass is the Mock-Crowd image that comes with the examples.

Anyone got any ideas?

Hi @Chris_Barry
Kind of hard to say from just the snippet… Also assuming that by the array inside the unity Editor stays at 0 you mean rawByteBufferAsync.
Can you give me a bit more info on how you are setting this up? When I try your code with a super basic script like this:

    public ARImageDetectionManager _arImageDetectionManager;
    public Texture2D someImg;
//...
    void Start()
    {
        AddImageToSession(someImg);   
    }
//...

I can see that the _yetiImage is added, and I can access info from it. so yea need a bit more info on this.

Hi Chris,

Unfortunately, I was unable to reproduce the issue you are observing. I could detect Yeti and Crowd images as in the ImageDetection example. I also detected the Mock-Crowd image by copying that jpg to the same directory as Yeti.jpg or Crowd.jpg, creating Mock-Crowd.jpg.bytes file and using it as Reference Image Input (in ExampleManager Inspector window).

Pls Note: The image Detection example works only on APP, not in the unity editor. So please try to deploy your app to the device and point toward the image to be detected.

Also can you please confirm that you have targeted the image which you want to load within Unity as well as the code? Please refer to this Image Detection documentation.

If the issue still persists, please reply to this post with any log information you are seeing, any screenshots with error messages, or any other details that you may have which might help us to repro the issue.

Thanks.

Hi,

When you say it only works on the app, does that mean I wouldn’t see the images in _arImageDetectionManager go up when adding them to that?

And also, if it only works in the app, why is there a Mock Image Anchor? Presumably you just mean the example you have built only works on the app, not that the whole image detection system doesn’t preview in editor?

I’ll try some more things out, but it sounds like you are confident something should be working my end, so I’ll keep trying.

Cheers,

Chris

Actually, I mean that the array inside the _arImageDetectionManager stays at 0, when I would expect to see a new element appear there

This element in the array is a hardcoded (editor added) one from the example scene in the latest sdk, so I would expect after running the code to see this array go up.

Here is an example (in the latest SDK and unity 2021.3.6f1)

Need to post seperate images

Nothing happens (the array does not increase in size) and no errors are generated.

Any ideas?

Manager next to script to add image programatically

And the code of that component

And I tried a different tex2d here:

Remember, the crowd element is a manual one in editor, I’d hope to see new elements popping up in the array…

Hi Chris,

Yes, as I mentioned earlier. No changes will show in the Unity editor because the image detection example scene only works on devices. Once you build an Image Detection scene on your device, you are able to detect an image with your phone camera and replace it with an AR asset.
Please see the attached screenshots for your reference.

Hi @Umaiya_Doddamani1 ,

Thanks for your feedback :slight_smile: OK, so I will have to assume this works and try on the device. What was confusing is that you said that the example scene does not work on the editor but only on device? That’s fine, but it’s the ARImageDetectionManager that I am trying to get that to work (in another scene, not inside the example scene, although I was trying that as well of course) so to be clear, it’s not possible to see ARImageDetectionManager running in the editor?

If this is the case, what is the point of having this mock - Detecting Images — Niantic Lightship Augmented Reality Developer Kit release-2.1 documentation

Kind regards,

Chris

Hi Chris,

The latest version of ARDK supports image detection in the unity editor, while the older versions do not. You can use the mock living room scene to detect yeti and crowd images. Here is the document for your reference.

The InspectorImage in the ARImageDetectionManager is used to provide a way to add reference images in the inspector, while the AddImage function call will not increase the array size.

Thanks,