Search Unity

Resolved Help using ViewportPointToRay and Face Detection

Discussion in 'AR' started by mattycorbett, Jul 20, 2022.

  1. mattycorbett

    mattycorbett

    Joined:
    May 9, 2021
    Posts:
    13
    I am working with MS FaceDetector and the RGB camera on a HoloLens2 to detect faces in 3D. The detection works great and I am getting detections with X,Y coordinates. The coordinated appear to check out when compared to the raw image. From there I use Unity’s ViewPortPointToRay to take the coordinates as a ratio of the height and width of the image, respectively. Problem is that the ray cast hit that results is always wildly low and to the left of the actual face and not in line with the coordinates when compared to the image. Any ideas?

    The code is:
    Ray ray = Camera.main.ScreenPointToRay(new Vector2((face.X / originalImageBitmap.PixelWidth) / tempCamera.pixelWidth, (((originalImageBitmap.PixelHeight-face.Y) / result.originalImageBitmap.PixelHeight))) / tempCamera.pixelHeight);

    where "face" is the object holding the detection, including X,Y coordinates and width/height of the bounding box.

    Using this, the raycast hit is always wildly low and left.
     
  2. mattycorbett

    mattycorbett

    Joined:
    May 9, 2021
    Posts:
    13
    I was able to fix this. The conversion to Vector3 was rounding the numbers to 0. The input was 0,0,0, which is the lower left. Stupid mistake.