Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

AR Foundation Simplified image recognition

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

  1. Juan_Luis

    Juan_Luis

    Joined:
    May 10, 2016
    Posts:
    5
    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. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,076
    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:
    5