o
    €o™iê  ã                
   @   sh   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 dej
dej
d	ej
d
ej
dej
f
dd„ZdS )z2Module with the functionalities for triangulation.é    N)Úzeros)ÚKORNIA_CHECK_SHAPE)Úconvert_points_from_homogeneous)Ú_torch_svd_castÚP1ÚP2Úpoints1Úpoints2Úreturnc                 C   sh  t | g d¢ƒ t |g d¢ƒ t |g d¢ƒ t |g d¢ƒ t|j|jƒ}t|dd… d ƒ |¡}tdƒD ]n}|d | dd	d
…|f  | ddd…|f  |dd|f< |d | dd	d
…|f  | ddd	…|f  |dd|f< |d |dd	d
…|f  |ddd…|f  |dd	|f< |d |dd	d
…|f  |ddd	…|f  |dd
|f< q4t|ƒ\}}}|d }	t|	ƒ}
|
S )a¬  Reconstructs a bunch of points by triangulation.

    Triangulates the 3d position of 2d correspondences between several images.
    Reference: Internally it uses DLT method from Hartley/Zisserman 12.2 pag.312

    The input points are assumed to be in homogeneous coordinate system and being inliers
    correspondences. The method does not perform any robust estimation.

    Args:
        P1: The projection matrix for the first camera with shape :math:`(*, 3, 4)`.
        P2: The projection matrix for the second camera with shape :math:`(*, 3, 4)`.
        points1: The set of points seen from the first camera frame in the camera plane
          coordinates with shape :math:`(*, N, 2)`.
        points2: The set of points seen from the second camera frame in the camera plane
          coordinates with shape :math:`(*, N, 2)`.

    Returns:
        The reconstructed 3d points in the world frame with shape :math:`(*, N, 3)`.

    )Ú*Ú3Ú4)r   ÚNÚ2Néÿÿÿÿ)é   r   r   ).r   .é   é   r   é   ).r   ).r   )r   ÚmaxÚshaper   Útype_asÚranger   r   )r   r   r   r	   Úpoints_shapeÚXÚiÚ_ÚVÚ
points3d_hÚpoints3d© r    úZ/home/ubuntu/.local/lib/python3.10/site-packages/kornia/geometry/epipolar/triangulation.pyÚtriangulate_points   s   6668r"   )Ú__doc__ÚtorchÚkornia.corer   Úkornia.core.checkr   Úkornia.geometry.conversionsr   Úkornia.utils.helpersr   ÚTensorr"   r    r    r    r!   Ú<module>   s"   ÿÿÿÿþ