How do I add images to ARImageDetectionManager at runtime

  • Issue category: Unity Example Package
  • Device type & OS version: Android
  • Host machine & OS version: Windows
  • Issue Environment : On Device
  • Xcode version:
  • ARDK version: 1.0.1
  • Unity version: 2020.2.2f1

I have been playing around with the ImageDetection example in the ARDK Examples folder and am trying to figure out if it is possible to add images to the ARImageDetectionManager at runtime.
I am trying to just use a Texture2D that is set in the editor and create a byte from that which is used in the ARReferenceImageFactory.Create call:

public void AddNewImageButtonClick () {
      byte[] pngImageData = newImageTexture.GetRawTextureData();

      IARReferenceImage newImageToAdd =
        ARReferenceImageFactory.Create
        (
          "newImage",
          pngImageData,
          500,
          500,
          ByteOrderInfo.big32, 
          AlphaInfo.First, 
          4, 
          _byteBufferImagePhysicalSize
        );

      _codeImageDetectionManager.AddImage(newImageToAdd);
}

Pressing this button in the scene after building to my phone does not give me any errors but when I log the array of images in the manager, it only shows the two example images in the list and not the one I added. When trying to scan the image I added at runtime, nothing happens. Appreciate the help!

Hello Emilio, when you run the example scene using the included images, does it work? Have you tried both the code and inspector created managers? Are you building this code off of the pre-existing ARImageDetectionManager.cs or ImageDetectionExampleManager.cs files? They contain helpful comments and code that would help provide an error log. Do you receive any warning messages? Is the image you are adding a jpg with .bytes extension?

From the ImageDetectionExampleManager.cs script:

// Create an ARReferenceImage from raw bytes. In a real application, these bytes

// could have been received over the network.

var rawByteBuffer = _byteBufferImageBytes.bytes;

_yetiImage =

  ARReferenceImageFactory.Create

  (

    "byteBufferImage",

    rawByteBuffer,

    rawByteBuffer.Length,

    _byteBufferImagePhysicalSize

  );



// Add both images to the manager.

_codeImageDetectionManager.AddImage(_yetiImage);

_codeImageDetectionManager.AddImage(imageFromPath);

}

Hi Emilio,

We haven’t heard back from you after requesting more information. Hopefully the issue has been resolved. As it has been some time, I’m going to wrap up this thread. However, if the issue persists please open a new topic.

Has this been resolved? I’m having the same issue, all images added via the inspector of ARImageDetectionManager work fine, but any images added via code do not get recognized, and do not throw errors. This does happen in the example scene as well as replicated in my own scripts.

In the example scene when I switch to code image detector it doesnt detect anything, but the inspector image detector does.

Edit: On further testing I’ve realized im dumb and didn’t actually assign the reference to the ImageDetectionManager. It works now.

However in the image detection sample scene, it will detect the code generated images, but only debugs that they are found, it doesnt spawn a plane as it seems to be intended to.

Hi Scott, that is a great question but it doesn’t look like it ever got answered on this thread. Can we ask you to open a new topic to get this issue back in front of the community?

1 Like

I found the error with Image detection Exaample manager with “Invalid Image Reference”, can someone help me on this.

Hello Dwiky, were you able to find a solution through the above troubleshooting? If not, please provide your use case, expected results, and copy/paste of your console error messages.