Packages/com.github.homuler.mediapipe/Runtime/Scripts/Unity/CoordinateSystem/CameraCoordinate.cs
/// <summary>
///   Convert from camera coordinates to local coordinates in Unity.
/// </summary>
/// <param name="rectTransform">
///   <see cref="RectTransform" /> to be used for calculating local coordinates
/// </param>
/// <param name="x">X in camera coordinates</param>
/// <param name="y">Y in camera coordinates</param>
/// <param name="z">Z in camera coordinates</param>
/// <param name="focalLength">Normalized focal lengths in image coordinates</param>
/// <param name="principalPoint">Normalized principal point in image coordinates</param>
/// <param name="zScale">Ratio of Z values in camera coordinates to local coordinates in Unity</param>
/// <param name="imageRotation">Counterclockwise rotation angle of the input image</param>
/// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
Convert from camera coordinates to local coordinates in Unity.
Convert from camera coordinates to local coordinates in Unity .
public static Vector3 GetLocalPosition(RectTransform rectTransform, float x, float y, float z, Vector2 focalLength, Vector2 principalPoint, float zScale, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false) {
      var pixelX = (-focalLength.x * x / z + principalPoint.x) / 2;
      var pixelY = (focalLength.y * y / z + principalPoint.y) / 2;
      var rect = rectTransform.rect;
      return RealWorldCoordinate.GetLocalPosition(rectTransform, pixelX, pixelY, -z, new Vector3(rect.width, rect.height, zScale), imageRotation, isMirrored);
    }
public static Vector3 GetLocalPosition ( RectTransform rectTransform , float x , float y , float z , Vector2 focalLength , Vector2 principalPoint , float zScale , RotationAngle imageRotation = RotationAngle . Rotation0 , bool isMirrored = false ) { var pixelX = ( - focalLength . x * x / z + principalPoint . x ) / 2 ; var pixelY = ( focalLength . y * y / z + principalPoint . y ) / 2 ; var rect = rectTransform . rect ; return RealWorldCoordinate . GetLocalPosition ( rectTransform , pixelX , pixelY , - z , new Vector3 ( rect . width , rect . height , zScale ) , imageRotation , isMirrored ) ; }
Convert from camera coordinates to local coordinates in Unity.
Convert from camera coordinates to local coordinates in Unity .
// Reverse the sign of Z because camera coordinate system is right-handed
rectTransform
RectTransform
to be used for calculating local coordinates
to be used for calculating local coordinates
x
float
X in camera coordinates
X in camera coordinates
y
float
Y in camera coordinates
Y in camera coordinates
z
float
Z in camera coordinates
Z in camera coordinates
focalLength
Vector2
Normalized focal lengths in image coordinates
Normalized focal lengths in image coordinates
principalPoint
Vector2
Normalized principal point in image coordinates
Normalized principal point in image coordinates
zScale
float
Ratio of Z values in camera coordinates to local coordinates in Unity
Ratio of Z values in camera coordinates to local coordinates in Unity
imageRotation
RotationAngle
Counterclockwise rotation angle of the input image
Counterclockwise rotation angle of the input image
isMirrored
bool
Set to true if the original coordinates is mirrored
Set to true if the original coordinates is mirrored