
    3jH                    b    S r SSKJr  SSKJr  SSKrSSKJr  S	S jr S
     SS jjr	S	S jr
g)zBnn.Module for the projection of points in the canonical z=1 plane.    )annotations)OptionalNKORNIA_CHECK_SHAPEc                D    [        U SS/5        U SSS24   U SSS24   -  $ )a  Project one or more points from the camera frame into the canonical z=1 plane through perspective division.

.. math::

    \begin{bmatrix} u \\ v \\ w \end{bmatrix} =
    \begin{bmatrix} x \\ y \\ z \end{bmatrix} / z

.. note::

    This function has a precondition that the points are in front of the camera, i.e. z > 0.
    If this is not the case, the points will be projected to the canonical plane, but the resulting
    points will be behind the camera and causing numerical issues for z == 0.

Args:
    points_in_camera: torch.Tensor representing the points to project with shape (..., 3).

Returns:
    torch.Tensor representing the projected points with shape (..., 2).

Example:
    >>> points = torch.tensor([1., 2., 3.])
    >>> project_points_z1(points)
    tensor([0.3333, 0.6667])

*3.N      r   )points_in_cameras    ^/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/geometry/camera/projection_z1.pyproject_points_z1r      s9    4 '#s4C!G$'7QqS'AAA    c                    [        U SS/5        Uc;  [        R                  " U R                  SS S-   U R                  U R
                  S9nOUR                  S   S:  a  US	   n[        R                  " X-  U/SS
9$ )a  Unproject one or more points from the canonical z=1 plane into the camera frame.

.. math::
    \begin{bmatrix} x \\ y \\ z \end{bmatrix} =
    \begin{bmatrix} u \\ v \end{bmatrix} \cdot w

Args:
    points_in_cam_canonical: torch.Tensor representing the points to unproject with shape (..., 2).
    extension: torch.Tensor representing the extension (depth) of the points to unproject with shape (..., 1).

Returns:
    torch.Tensor representing the unprojected points with shape (..., 3).

Example:
    >>> points = torch.tensor([1., 2.])
    >>> extension = torch.tensor([3.])
    >>> unproject_points_z1(points, extension)
    tensor([3., 6., 3.])

r   2N)   )devicedtyper   r   ).Ndim)r   torchonesshaper   r   cat)points_in_cam_canonical	extensions     r   unproject_points_z1r   <   s    . .c
;JJ#))#2.5*11)//
	
 
	a	i(	99-99E2NNr   c           	        [        U SS/5        U S   nU S   nU S   nSU-  nXD-  n[        R                  " U5      n[        R                  " [        R                  " XFU* U-  /SS9[        R                  " XdU* U-  /SS9/S	S9$ )
a
  Compute the derivative of the x projection with respect to the x coordinate.

Returns point derivative of inverse depth point projection with respect to the x coordinate.

.. math::
    \frac{\partial \pi}{\partial x} =
    \begin{bmatrix}
        \frac{1}{z} & 0 & -\frac{x}{z^2} \\
        0 & \frac{1}{z} & -\frac{y}{z^2}
    \end{bmatrix}

.. note::
    This function has a precondition that the points are in front of the camera, i.e. z > 0.
    If this is not the case, the points will be projected to the canonical plane, but the resulting
    points will be behind the camera and causing numerical issues for z == 0.

Args:
    points_in_camera: torch.Tensor representing the points to project with shape (..., 3).

Returns:
    torch.Tensor representing the derivative of the x projection with respect to the x coordinate
    with shape (..., 2, 3).

Example:
    >>> points = torch.tensor([1., 2., 3.])
    >>> dx_project_points_z1(points)
    tensor([[ 0.3333,  0.0000, -0.1111],
            [ 0.0000,  0.3333, -0.2222]])

r   r	   ).r   ).r   ).r
   g      ?r   r   )r   r   
zeros_likestack)r   xyzz_invz_sqzeross          r   dx_project_points_z1r)   a   s    > '#s4 A A A!GE=DU#E;;KKrDy1r:KKrDy1r:	
  r   )r   torch.Tensorreturnr*   )N)r   r*   r   zOptional[torch.Tensor]r+   r*   )__doc__
__future__r   typingr   r   kornia.core.checkr   r   r   r)    r   r   <module>r1      sM   $ I #   0B> PT"O)"O6L"O"OJ.r   