Search Unity

  1. Unity 2019.4 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  3. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

AR Foundation Simplified image recognition

Discussion in 'Handheld AR' started by Juan_Luis, Jun 15, 2020.

  1. Juan_Luis

    Juan_Luis

    Joined:
    May 10, 2016
    Posts:
    3
    Hello, I have a question,

    Could you with ImageTracking use a simplified image instead of a real image?

    For example, I have an image of a car with two wheels and two windows. But instead of using that image, I want to use with two squares and two circles, so I can use ImageTracking with two different cars.

    Thanks
     
  2. KirillKuzyk

    KirillKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    111
    Yes, this is possible. You simply need to write your own image visualizer and replace detected image by a real one.
    Here is an idea:
    Code (CSharp):
    1. using System.Linq;
    2. using UnityEngine;
    3. using UnityEngine.Assertions;
    4. using UnityEngine.XR.ARFoundation;
    5.  
    6.  
    7. public class TrackedImagesVisualizer : MonoBehaviour {
    8.     [SerializeField] ARTrackedImageManager manager = null;
    9.  
    10.  
    11.     void Awake() {
    12.         manager.trackedImagesChanged += trackedImagesChanged;
    13.     }
    14.  
    15.     void OnDestroy() {
    16.         manager.trackedImagesChanged -= trackedImagesChanged;
    17.     }
    18.  
    19.     void trackedImagesChanged(ARTrackedImagesChangedEventArgs args) {
    20.         foreach (var trackedImage in args.added.Concat(args.updated)) {
    21.             // todo set scale and position
    22.             var mr = trackedImage.transform.GetComponentInChildren<MeshRenderer>();
    23.             Assert.IsNotNull(mr);
    24.             mr.material.mainTexture = getRealImage(trackedImage.referenceImage.name);
    25.         }
    26.     }
    27.  
    28.     Texture getRealImage(string imageName) {
    29.         throw new System.NotImplementedException("todo: replace detected image with real one");
    30.     }
    31. }
    32.  
     
  3. Juan_Luis

    Juan_Luis

    Joined:
    May 10, 2016
    Posts:
    3
unityunity