Log in or register to post comments

How to dynamically change image target image

April 1, 2020 - 4:42am #1

How do I change the image of a target by scripting?

Just like you can change an UI image with gameObject.Find("Image").getComponent<Image>().sprite = customimage;

 

How to dynamically change image target image

October 1, 2021 - 9:59pm #19

tracking is not at all working in my case and i am getting same error Instant image target at 'Vuforia/machines.jpg' could not be created

i tried all below option

- tried adding mesh renderer

-correct size of image target

- since there is no option to set image for image target through script so that option is not available

- image type is checked

-checked if image exist in correct folder or not 

-checked if data set exists or not 

Still not worked

unity 2019.4.01f1 and vuforia 9.8.11 and tried for both android and windows . didnt work. kindly guide.

How to dynamically change image target image

January 11, 2021 - 1:28am #18

Hi,

In my tests tracking/recognition was working as expected.

Thank you.

Vuforia Engine Support

How to dynamically change image target image

January 9, 2021 - 6:42am #17

Hi. I know this thread is old, but i hope someone to reply.

I've encountered the same issue. tracking seems to work, but "image" field rest unpopulated.

My application get images from a webserver and create image targes and object to spawn at rutime (this allows me to update the web database without the need to update the application)

"Image" field is not accessible by script, hence I can't set an image directly.

If you assure me the tracking will be stable even with empty field, the issue is no more.

 

 

 

How to dynamically change image target image

April 21, 2020 - 3:56am #16

Hi,

I quickly tested it with an image downloaded from Internet and also via from storage. In both cases the field Texture is not populated. However recognition and tracking work as expected.

The error mentioned in the last post, seems to only occur after you try to add it in via editor.

Do you need to modify that field? or is tour recognition and tracking not working at all?

Thank you.

Vuforia Engine Support

 

How to dynamically change image target image

April 21, 2020 - 3:28am #15

Hey,

The problem is that the code does not set the target image texture. It also gives an error about not having a renderer attached when you add an image manually so I think thats also a problem.

I have added a screenshot for more clarity.

I really appreciate your time helping me, been stuck on this for a while.

My thanks.

AttachmentSize
Image icon 2020_04_21_12_25_48_.png248.19 KB

How to dynamically change image target image

April 21, 2020 - 3:19am #14

Hi,

You will need to attach a GameObject to it. In the code snippet we have at the end a comment // TODO: add virtual content as child object(s)

For example, try adding the below code, this will create a primitive GameObject.



                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

                sphere.transform.SetParent(trackableBehaviour.gameObject.transform);

Hope this answers your question.

Vuforia Engine Support

How to dynamically change image target image

April 21, 2020 - 1:31am #13

Hello,

I have tried the code on the website you gave me and I cant get it to work.

Right now its creating 2 new objects, 1 object called "new game object" with only an empty image target behavior, and another called the way I said it to call it that does not load the image and does not have a mesh renderer wich I also cant give it with code. (see images).

This is the code im using:

using UnityEngine;

using UnityEngine.Networking;

using System.Collections;

using Vuforia;

public class DownLoadIT : MonoBehaviour

{

    void Start()

    {

        StartCoroutine(CreateImageTargetFromDownloadedTexture());

    }

    IEnumerator CreateImageTargetFromDownloadedTexture()

    {

        using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("https://vuforialibrarycontent.vuforia.com/Images/devGuide_ImageTargets.jpg"))

        {

            yield return uwr.SendWebRequest();

            if (uwr.isNetworkError || uwr.isHttpError)

            {

                Debug.Log(uwr.error);

            }

            else

            {

                var objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();

                // Get downloaded texture once the web request completes

                var texture = DownloadHandlerTexture.GetContent(uwr);

                // get the runtime image source and set the texture

                var runtimeImageSource = objectTracker.RuntimeImageSource;

                runtimeImageSource.SetImage(texture, 0.15f, "target");

                // create a new dataset and use the source to create a new trackable

                var dataset = objectTracker.CreateDataSet();

                var trackableBehaviour = dataset.CreateTrackable(runtimeImageSource, "target");

                // add the DefaultTrackableEventHandler to the newly created game object

                trackableBehaviour.gameObject.AddComponent<DefaultTrackableEventHandler>();

                //trackableBehaviour.gameObject.AddComponent<MeshRenderer>();

                //trackableBehaviour.gameObject.AddComponent<TurnOffBehaviour>();

                // activate the dataset

                objectTracker.ActivateDataSet(dataset);

                // TODO: add virtual content as child object(s)

            }

        }

    }

}

 

 

 



 

AttachmentSize
Image icon createdtargets.png3.15 KB
Image icon targetinfo.png61.69 KB
Image icon randomtargetinfo.png35.24 KB

How to dynamically change image target image

April 8, 2020 - 1:25am #12

Hi,

Glad that you solved the issue!

As far as I know we don't have any limitations. In the script, to be more specific here: runtimeImageSource.SetImage(texture, 0.15f, "myTargetName");

0.15f -> is the width and is in meters

The size of the physical image needs to match the width you entered in the script for an optimal tracking experience.

Thank you.

Vuforia Engine Support

How to dynamically change image target image

April 7, 2020 - 7:43am #11

Hi,

It was indeed the size (height,width) of the image which was the problem

Do you know which are the max width and height allowed ?

Thanks

How to dynamically change image target image

April 7, 2020 - 7:18am #10

Hi,

 

I triple checked my webserver and i am really sure that i can access the pictures without authentication. Did your test of copy pasting the url and it works.

when i save your test image on my webserver it also works so i'm pretty sure its related to the image3

I have compared both of the texture with visual studio debugging (see the attachment. left side texture of mine webserver image, right side texture of your testimage saved on my webserver)

I dont see many difference except the height and size so i hope the error is related to that.

Gonna test with smaller images and will let you know.

 

Thanks for the quick responses

AttachmentSize
Image icon CompareTextureDetails.jpg406.18 KB

How to dynamically change image target image

April 7, 2020 - 6:52am #9

Hi,

I wanted to underline that you need to specify the exact file with the ".jpg" statement. My understanding is that .jpg or .png should work. You could also try it .jpeg :)

The issue may by with your webserver, do you require authentication? A quick test, would be to copy paste the link with the picture, into a browser and see if you get get the image or an autentication prompt.

Thank you.

Vuforia Engine Support

How to dynamically change image target image

April 7, 2020 - 5:48am #8

Hi thanks for your help.

 

I managed to get it to work with your given jpg url.

The problem is that the image that i was trying is a .jpeg instead of a .jpg.

 

Is there any possible solutions to make it work with .jpeg?

 

[EDIT]

I just tried with a .jpg on my webserver and it stil doesnt work. Are there any other requirements on the images then just the .jpg extension ?

[EDIT]

 

Thank you in advance

How to dynamically change image target image

April 7, 2020 - 4:56am #7

Hi,

Did you attach the script to the AR Camera?

Also make sure that the web link is ".jpg"

Try this web image: https://vuforialibrarycontent.vuforia.com/Images/devGuide_ImageTargets.jpg stored in the library: https://library.vuforia.com/content/vuforia-library/en/articles/Training/Image-Target-Guide.html

Let me know if its works with  the above web image.

Thank you.

Vuforia Engine Support

How to dynamically change image target image

April 7, 2020 - 3:30am #6

Hello,

 

I just tried the guide you posted but i am not capable to make "download a texture image from a web URL and generate an image target from it." working.

it goes wrong in this part:

RuntimeImageSource runtimeImageSource = objectTracker.RuntimeImageSource;

runtimeImageSource.SetImage(texture, 0.15f, "onlinetarget");

The error that appears in the console is "Instant image target 'onlinetarget' could not be created"

 

Thank you in advance

How to dynamically change image target image

April 6, 2020 - 8:38am #5

Hi,

In this article we go through the process: https://library.vuforia.com/content/vuforia-library/en/articles/Solution/how-to-create-and-load-targets-in-unity.html of creating Image Targets from images at Run-time.

Thank you.

Vuforia Engine Support

 

 

How to dynamically change image target image

April 6, 2020 - 5:58am #4

Sorry for the late reaction, but basically I want to dynamically load different targets from my mysql database on runtime. I already can load the images and have it stored in a variable, now I only have to make it a target.

How to dynamically change image target image

April 2, 2020 - 9:36am #3

Same here. I have a template gameobject with multiple components that I want to re-use in my scene. I have a Image Target Behaviour component assigned with image type "From Image" set. How do I change the Image parameter on this component?

How to dynamically change image target image

April 2, 2020 - 1:33am #2

Hi,

In order to create Image Targets, you can use the Target Manager or use Insta Image Targets (which creates Image Targets at Run-time). The high level process entails that the picture used, is analyzed and feature points are extracted. This feature points will assist in detecting the used picture. If you would change the image/picture from the Image Target, Vuforia will not detect the features hence there will be no augmentation.

We don't recommended changing the image from an Image Target as in the end the recognition process will not work.

Could you please elaborate on why do you want to change the Image? Based on that I can provide a workaround.

Thank you.

Vuforia Engine Support

Log in or register to post comments