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. Dismiss Notice

ARFoundation Camera Position based on Tracked image

Discussion in 'AR' started by Elnazt, May 30, 2020.

  1. Elnazt


    Mar 25, 2020
    When I run my AR project on an iPhone X, it initially shows the AR camera's position as (0,0,0) using arcamera.transform.location and then it keep updating as I move the camera around. When I use my QR code to instantiate a prefab in the scene using AR Tracked Image Manager, it shows the location of my QR code to be (0,0,0) as well which matches the Unity scene. Is there a way to find the actual location of the AR camera, after finding the tracked image in the scene? I am using ARFoundation version 4.0.0.
  2. laurenta35


    Jun 23, 2015
    Do you mean you'd like to get the tracked image's world position? This is also an information I'd like to know how to retrieve.
    Or said in a different manner: how to get the camera pose with respect to the tracked image?
    Last edited: Jun 9, 2020
  3. erudite_1


    May 24, 2022
    Hi @Elnazt I also have the similar requirement like you. Did you find any solution?
  4. mikeyrafier98


    May 19, 2022
    It is the coordinate relationship you are talking about, I think. I hope this answer can help.


    In order to transform the coordinate from camera to marker coordinate system, simply we need to see their coordinate relationship. First, let's see what we have on the picture I attached.
    - system automatically calculate camera to world coordinate origin (Wo)
    - once camera found the marker, system automatically calculate marker to world coordinate origin (Wo)
    Our goal is to find where the camera position by the marker coordinate system (Mc)

    Matrix4x4, you can get this easily in Unity by:
    1. for object to Wo
    Code (CSharp):
    1. object.transform.localToWorldMatrix;
    2. for Wo to object, or as same as invert matrix (1)
    Code (CSharp):
    1. object.transform.worldToLocalMatrix;
    We already know the position (Vector3) of the camera in world coordinate system, and we have these matrices.
    Calculate all of these will result you the position (Vector3) of the camera in marker coordinate system.

    Does this what we are looking for?
    Please let me know if I misunderstand thing.