a
    ždX  ć                   @   sZ   d dl mZ d dlZd
ejejeejdddZdejejejeej ejddd	ZdS )é    )ŚOptionalNF)ŚtauxŚtauyŚreturn_inverseŚreturnc                 C   s°  | j |j kr&td| j  d|j  d|  ” }|  d”} | d”}t | ”}t | ”}t |”}t |”}t |”}t |”}	t 	|	||||||| |g	d” ddd”}
t 	||| ||	||||g	d” ddd”}||
 }|rLd|d  }t 	|||d | |||d	 | |||	g	d” ddd”}| 
dd
”| }|dkrHt |”}|S t 	|d ||d  ||d |d	  |||	g	d” ddd”}|| 
dd
” }|dkr¬t |”}|S )aŚ  Estimate the tilt projection matrix or the inverse tilt projection matrix.

    Args:
        taux: Rotation angle in radians around the :math:`x`-axis with shape :math:`(*, 1)`.
        tauy: Rotation angle in radians around the :math:`y`-axis with shape :math:`(*, 1)`.
        return_inverse: False to obtain the the tilt projection matrix. True for the inverse matrix.

    Returns:
        torch.Tensor: Inverse tilt projection matrix with shape :math:`(*, 3, 3)`.
    zShape of taux z
 and tauy z do not match.é’’’’é   é   ).é   r
   ).r   r
   ).r	   r
   éž’’’r   )ŚshapeŚ
ValueErrorŚdimZreshapeŚtorchŚcosŚsinZ
zeros_likeŚ	ones_likeŚstackŚ	transposeZsqueeze)r   r   r   ŚndimZcTxZsTxZcTyZsTyZzeroZoneZRxZRyŚRZinvR22ZinvPzZinv_tiltZPzŚtilt© r   śl/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/kornia/geometry/calibration/distort.pyŚtilt_projection   sD    







**&’ž

*’ž

r   )ŚpointsŚKŚdistŚnew_Kr   c                 C   s¦  |   ” dk r,| jd dkr,td| j d|jdd dkrPtd|j d|du r^|}n$|jdd dkrtd	|j d|jd d
vr¤td|jd  |jd dk rŠtjj |dd|jd  g”}|ddddf }|ddddf }|ddddf }|ddddf }| d | | }| d | | }	|| |	|	  }
d|dddf |
  |dddf |
 |
  |dddf |
d   d|dddf |
  |dddf |
 |
  |dddf |
d    }|| d|dddf  | |	  |dddf |
d| |    |dddf |
  |dddf |
 |
  }|	| |dddf |
d|	 |	    d|dddf  | |	  |dddf |
  |dddf |
 |
  }t |d dk”sąt |d dk”r6t|d |d }t 	||t 
|”gd”| dd” }|d |d  }|d |d  }|ddddf }|ddddf }|ddddf }|ddddf }|| | }|| | }	t 	||	gd”S )a}  Distortion of a set of 2D points based on the lens distortion model.

    Radial :math:`(k_1, k_2, k_3, k_4, k_4, k_6)`,
    tangential :math:`(p_1, p_2)`, thin prism :math:`(s_1, s_2, s_3, s_4)`, and tilt :math:`(\tau_x, \tau_y)`
    distortion models are considered in this function.

    Args:
        points: Input image points with shape :math:`(*, N, 2)`.
        K: Intrinsic camera matrix with shape :math:`(*, 3, 3)`.
        dist: Distortion coefficients
            :math:`(k_1,k_2,p_1,p_2[,k_3[,k_4,k_5,k_6[,s_1,s_2,s_3,s_4[,\tau_x,\tau_y]]]])`. This is
            a vector with 4, 5, 8, 12 or 14 elements with shape :math:`(*, n)`.
        new_K: Intrinsic camera matrix of the distorted image. By default, it is the same as K but you may additionally
            scale and shift the result by using a different matrix. Shape: :math:`(*, 3, 3)`. Default: None.

    Returns:
        Undistorted 2D points with shape :math:`(*, N, 2)`.

    Example:
        >>> points = torch.rand(1, 1, 2)
        >>> K = torch.eye(3)[None]
        >>> dist_coeff = torch.rand(1, 4)
        >>> points_dist = distort_points(points, K, dist_coeff)
    r
   r   zpoints shape is invalid. Got Ś.r   N)r   r   zK matrix shape is invalid. Got z#new_K matrix shape is invalid. Got )é   é   é   é   é   z/Invalid number of distortion coefficients. Got r$   r   .r	   ).r   ).r	   r    r!   r   é   é   r"   é	   é
   é   r#   ).r#   ).é   ).r
   )r   r   r   r   ŚnnZ
functionalŚpadŚanyr   r   r   r   )r   r   r   r   Znew_cxZnew_cyZnew_fxZnew_fyŚxŚyZr2Zrad_polyZxdZydr   Zpoints_untiltZcxŚcyZfxZfyr   r   r   Śdistort_points;   sl    FF’’žżü’’žżü’	($r1   )F)N)Śtypingr   r   ZTensorŚboolr   r1   r   r   r   r   Ś<module>   s   5 ’ž