o
    oi                     @   s|   d dl Z d dlm  mZ d dlmZmZmZm	Z	 de j
de j
de j
fddZ	dd	e j
d
e j
de j
dede j
f
ddZdS )    N)convert_points_from_homogeneousconvert_points_to_homogeneous"denormalize_points_with_intrinsics normalize_points_with_intrinsicspoint_3dcamera_matrixreturnc                 C   s   t | }t||S )a[  Project a 3d point onto the 2d camera plane.

    Args:
        point_3d: tensor containing the 3d points to be projected
            to the camera plane. The shape of the tensor can be :math:`(*, 3)`.
        camera_matrix: tensor containing the intrinsics camera
            matrix. The tensor shape must be :math:`(*, 3, 3)`.

    Returns:
        tensor of (u, v) cam coordinates with shape :math:`(*, 2)`.

    Example:
        >>> _ = torch.manual_seed(0)
        >>> X = torch.rand(1, 3)
        >>> K = torch.eye(3)[None]
        >>> project_points(X, K)
        tensor([[5.6088, 8.6827]])

    )r   r   )r   r   	xy_coords r
   V/home/ubuntu/.local/lib/python3.10/site-packages/kornia/geometry/camera/perspective.pyproject_points   s   
r   Fpoint_2ddepth	normalizec                 C   sj   t |tjstdt| |jd dkstd|j t| |}t|}|r1t	j
|ddd}|| S )a  Unproject a 2d point in 3d.

    Transform coordinates in the pixel frame to the camera frame.

    Args:
        point_2d: tensor containing the 2d to be projected to
            world coordinates. The shape of the tensor can be :math:`(*, 2)`.
        depth: tensor containing the depth value of each 2d
            points. The tensor shape must be equal to point2d :math:`(*, 1)`.
        camera_matrix: tensor containing the intrinsics camera
            matrix. The tensor shape must be :math:`(*, 3, 3)`.
        normalize: whether to normalize the pointcloud. This
            must be set to `True` when the depth is represented as the Euclidean
            ray length from the camera position.

    Returns:
        tensor of (x, y, z) world coordinates with shape :math:`(*, 3)`.

    Example:
        >>> _ = torch.manual_seed(0)
        >>> x = torch.rand(1, 2)
        >>> depth = torch.ones(1, 1)
        >>> K = torch.eye(3)[None]
        >>> unproject_points(x, depth, K)
        tensor([[0.4963, 0.7682, 1.0000]])

    z,Input depth type is not a torch.Tensor. Got    z0Input depth must be in the shape of (*, 1). Got g       @)dimp)
isinstancetorchTensor	TypeErrortypeshape
ValueErrorr   r   Fr   )r   r   r   r   xyxyzr
   r
   r   unproject_points9   s   
r   )F)r   torch.nn.functionalnn
functionalr   kornia.geometry.conversionsr   r   r   r   r   r   boolr   r
   r
   r
   r   <module>   s    