Search Unity

Position a label on a face

Discussion in 'VR' started by CharlesDel, Jul 23, 2019.

  1. CharlesDel

    CharlesDel

    Joined:
    Jul 23, 2019
    Posts:
    1
    Hi all,

    I try to put a label on a face.

    I use that 2 tutorials to find a solution (sorry I can't put link, I don't know why):
    mr-azure-304
    mr-azure-310

    both tutorials are on Microsoft website

    I use this function to find the face in the quad:
    Code (CSharp):
    1. /// <summary>
    2.     /// This method hosts a series of calculations to determine the position
    3.     /// of the Bounding Box on the quad created in the real world
    4.     /// by using the Bounding Box received back alongside the Best Prediction
    5.     /// </summary>
    6.     public Vector3 CalculateBoundingBoxPosition(Bounds b, BoundingBox boundingBox)
    7.     {
    8.         Debug.Log($"BB: left {boundingBox.left}, top {boundingBox.top}, width {boundingBox.width}, height {boundingBox.height}");
    9.  
    10.         double centerFromLeft = boundingBox.left + (boundingBox.width / 2);
    11.         double centerFromTop = boundingBox.top + (boundingBox.height / 2);
    12.         Debug.Log($"BB CenterFromLeft {centerFromLeft}, CenterFromTop {centerFromTop}");
    13.  
    14.         double quadWidth = b.size.normalized.x;
    15.         double quadHeight = b.size.normalized.y;
    16.         Debug.Log($"Quad Width {b.size.normalized.x}, Quad Height {b.size.normalized.y}");
    17.  
    18.         double normalisedPos_X = (quadWidth * centerFromLeft) - (quadWidth/2);
    19.         double normalisedPos_Y = (quadHeight * centerFromTop) - (quadHeight/2);
    20.  
    21.         return new Vector3((float)normalisedPos_X, (float)normalisedPos_Y, 0);
    22.     }

    My problem is when I receive the bouding box I have pixel and my quand is another unit. when I give that vector to my label, my label is far of the face.

    Do you have an idea how can I do that? I know the size of the picture, the size of the quad but I think my quad can be bigger then my picture.

    Thanks guys!