Search Unity

Using image to trigger object placement

Discussion in 'AR' started by straylight, Oct 9, 2019.

  1. straylight

    straylight

    Joined:
    Jan 7, 2013
    Posts:
    17
    Hi.

    Is there a way to use an image to trigger the placement of an object that will persist on the ground plane even when the image is too far (small) to be recognised? So I envisage a user using a phone to scan a small QR code that then triggers the placement of a large 3D virtual sculpture on the ground that the user must step back from to view entirely at which point the QR code would be too small to be recognised but the sculpture would persist for the duration of the session. I'm looking at image tracking example in AR Foundation but I don't think this uses ground plane detection. Any help appreciated.

    J
     
  2. digableMatt

    digableMatt

    Joined:
    Dec 7, 2016
    Posts:
    11
    Have you tried anything yet? Image recognition works pretty well right now, and keeps the placement even when you turn around and walk away. How far do you plan on moving away?
     
  3. straylight

    straylight

    Joined:
    Jan 7, 2013
    Posts:
    17
    Hi. Yes I got it working. I added a plane tracker and the object is bolted to the floor now even when you cant see the original image! Now I'm trying to figure out how to instantiate multiple sculptures from different images (hopefully keep all five in memory at once).
     
    tomassev likes this.
  4. digableMatt

    digableMatt

    Joined:
    Dec 7, 2016
    Posts:
    11
    Thats great! Glad to hear you got that working. As far as instantiate multiple sculptures from different images, you'll want to run your app and print out the name of the image it detects and grab them from the console. I had to do this with object recognition since I couldn't find a way to get the name of the .arobject from the RerferenceObjectLibrary.

    So I did:
    print(args.added[0].name);

    and when it would recognize an object I would get:
    ARTrackedObject 4782472E544C80BB-202CBE48F80584C4

    These ids are unique and persist across sessions and even devices so i'm guessing the id is derived from the name you give it. Knowing the various ids of the objects I was tracking I did a simple switch, which then changed various text game objects and even fired off animations based on what it detected. You could do the same thing, but place your various sculptures based on a switch. You just need to know the ids of the images it is detecting.
     
    straylight likes this.
  5. kfujii

    kfujii

    Joined:
    Feb 9, 2018
    Posts:
    1
    Would like to follow up with this...

    I'm trying to do something similar, where the user scans a QR code and a set environment is instantiated a set distance in front of the code – the user walks past the QR code and the gameobject is persistently tracked on the ground plane.

    Right now with the image tracking example on AR Foundation has the instantiated prefab locked to the position and rotation of the image. Would love to get some guidance, especially about instantiating the gameobject based off the position of the QR Code.
     
    kutlumete likes this.
  6. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    I am doing raycasts up and down and instantiate the object where the raycast hits the ground
     
  7. sidbhise

    sidbhise

    Joined:
    May 13, 2020
    Posts:
    7
    Even I'm trying to find a way to instantiate an object on the scanned QRCode. Any pointers would be of great help.
    Thanks in advance.
     
  8. StefanoCecere

    StefanoCecere

    Joined:
    Jun 10, 2011
    Posts:
    211
    i am dealing, too, with image tracking -> instantiate 3D object persisted in the real world with a 1:1 position.

    (i am using the position of the instatiated prefab)

    i'm checking if i need to add plane trackers to improve the persistance

    or how much "pre- scanning" of the environment i have to do before tracking the image..

    i haven't yet a final optimal solution
     
    kutlumete and unnanego like this.
  9. jiungerich

    jiungerich

    Joined:
    Jul 26, 2019
    Posts:
    18
    You could likely use methods similar to those used for spawning multiple prefabs - albeit modified for your case. You basically use event.args from the tracked image to spawn your prefab instead of relying on the prefab built into the the tracked image manger. I haven't tried this specifically but have use the multiple prefabs code. You basically just use the a similar method but ignore/remove the eventargs.removed section to keep the prefab active. A video of this method (for multiple prefabs) is here :



    Also after using any Ar tracked image code, I find the AR camera does lose it's it bearings so the prefabs will often drift. Not sure how to cure that.
     
  10. jiungerich

    jiungerich

    Joined:
    Jul 26, 2019
    Posts:
    18
    Just a note to the above as I just found this out myself. The example in the video above only sets the position - whereas one needs to set both position and rotation. Also there is an issue with ARCore(Android) where tracking goes to a limited state but never the removed state. This code from the AR foundation Demos is the best for all the cases dealing with instantiating with image tracking.

    https://github.com/Unity-Technologi...racking/Scripts/ImageTrackingObjectManager.cs
     
    unnanego likes this.
  11. tomassev

    tomassev

    Joined:
    Aug 24, 2014
    Posts:
    4
    Hi I am dealing with same issue could you please advice me. I am not sure what is best way. My idea is that I will have couple QR codes and I will get somehow location where is code scanned and under that I will update position of my model on floor
     
  12. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    I did it like this - first the user places an invisible ground plane that shows shadows and then when the user scans a marker, I did two raycasts (or more if you need) onto the ground or scanned planes and spawned the objects at intersection.
     
    tomassev likes this.