a
    þd!  ã                   @   s<   d Z ddlZddlmZ ejejejejejdœdd„ZdS )z1Module with the functionalites for triangulation.é    N)Úconvert_points_from_homogeneous)ÚP1ÚP2Úpoints1Úpoints2Úreturnc                 C   sp  t | jƒdkr | jdd… dks*t| jƒ‚t |jƒdkrJ|jdd… dksTt|jƒ‚t | jdd… ƒt |jdd… ƒkr†t| j|jƒ‚t |jƒdkr¢|jd dks¬t|jƒ‚t |jƒdkrÈ|jd dksÒt|jƒ‚t |jdd… ƒt |jdd… ƒkrt|j|jƒ‚t | jdd… ƒt |jdd… ƒkr:t| j|jƒ‚t|j|jƒ}t |dd… d ¡ |¡}tdƒD ]Þ}|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< qlt |¡\}}}|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)`.
    é   éþÿÿÿN)é   é   éÿÿÿÿ)r   r   r   ).r   .r
   r   é   ).r   ).r   )
ÚlenÚshapeÚAssertionErrorÚmaxÚtorchÚzerosZtype_asÚrangeZsvdr   )r   r   r   r   Zpoints_shapeÚXÚiÚ_ÚVZ
points3d_hZpoints3d© r   úo/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/kornia/geometry/epipolar/triangulation.pyÚtriangulate_points
   s2     
 
$

&&666:r   )Ú__doc__r   Zkornia.geometry.conversionsr   ZTensorr   r   r   r   r   Ú<module>   s
   þ