o
    'j                     @   sh   d dl Zd dlZd dlZdddZdddZdddZd	d
 ZdddZdddZ	dddZ
dd ZdS )    N   c                 C   s   | j \}}}|}|}||krt|| }nt|| }t|| }t|| }d}|| d | | }|| d | | }t| t|t|f} |t| }	|t| }
| |	|
ffS )z
    resize image to a size multiple of max_stride which is required by the network
    :param im: the resized image
    :param max_side_len: limit of max image size to avoid out of memory in gpu
    :return: the resized image and the resize ratio
          shapefloatintcv2resizeZimZmax_side_lenhw_Zresize_wZresize_hratioZ
max_strideZratio_hZratio_w r   g/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddleocr/ppocr/utils/e2e_utils/visual.pyresize_image   s   r   c                 C   s   | j \}}}|}|}||k rt|| }nt|| }t|| }t|| }d}|| d | | }|| d | | }t| t|t|f} |t| }	|t| }
| |	|
ffS )
    r   r   r   r   r   r   r   resize_image_min1   s   r   c                 C   s   | j \}}}|}|}d}|| |krt|| }t|| }t|| }d}|| d | | }|| d | | }t| t|t|f} |t| }	|t| }
| |	|
ffS )r   g      ?r   r   r   r   r   r   r   resize_image_for_totaltextJ   s   r   c                 C   s   g }| D ]}t j|d |d  }|| qt |}| | | f}t| d }dg| }t	| D ]\}}|d ||< |d ||d | < q7t |
dd|fS )zE
    Transfer vertical point_pairs into poly point in clockwise.
    r   r      )nplinalgnormappendarraymaxminmeanlen	enumerateZreshape)Zpoint_pair_listZpair_length_listZ
point_pairZpair_lengthZ	pair_info	point_numZ
point_listidxr   r   r   point_pair2polya   s   

r$                 ?c                 C   sr   t j|g|ggt jd}| d | d | d  |  }| d | d | d  |  }t |d |d |d |d gS )z+
    Generate shrink_quad_along_width.
    Zdtyper   r      r   )r   r   float32)ZquadZbegin_width_ratioZend_width_ratioZ
ratio_pairZp0_1Zp3_2r   r   r   shrink_quad_along_widthu   s   "r*   333333?c           	      C   sD  | j d }tj| d | d | d | d gtjd}| tj|d |d   tj|d |d  d  }t||d}tj| |d	 d	  | |d	 d  | |d	  | |d	 d  gtjd}d|tj|d |d   tj|d |d  d   }t|d
|}|d | d< |d | d< |d | |d	 d < |d	 | |d	 < | S )z"
    expand poly along width.
    r   r   r   r'   r(   gư>r&   r   r%   )r   r   r   r)   r   r   r*   )	ZpolyZshrink_ratio_of_widthr"   Z	left_quadZ
left_ratioZleft_quad_expandZ
right_quadZright_ratioZright_quad_expandr   r   r   expand_poly_along_width   s2   
r-   c                 C   s0   |rt t j| d |dS t t | d S )Nr   )axis)r   sqrtsum)xr.   r   r   r   norm2   s   r2   c                 C   s   | |   t| t|  S N)r0   r2   )p1Zp2r   r   r   cos   s   r5   )r   )r%   r&   )r+   r3   )numpyr   r	   timer   r   r   r$   r*   r-   r2   r5   r   r   r   r   <module>   s   





