
    i                     d    S SK rS SKrS SKrS
S jrS
S jrS
S jrS rSS jrSS jr	SS jr
S	 rg)    Nc                 p   U R                   u  p#nUnUnXe:  a  [        U5      U-  nO[        U5      U-  n[        Xg-  5      n[        XW-  5      nSnXh-   S-
  U-  U-  nXX-   S-
  U-  U-  n[        R                  " U [        U5      [        U5      45      n U[        U5      -  n	U[        U5      -  n
X	U
44$ )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immax_side_lenhw_resize_wresize_hratio
max_strideratio_hratio_ws              f/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddleocr/ppocr/utils/e2e_utils/visual.pyresize_imager      s     hhGA!HHl#h.l#h.8#$H8#$HJ%)j8:EH%)j8:EH	BXH6	7Bq!Gq!G!!!    c                 p   U R                   u  p#nUnUnXe:  a  [        U5      U-  nO[        U5      U-  n[        Xg-  5      n[        XW-  5      nSnXh-   S-
  U-  U-  nXX-   S-
  U-  U-  n[        R                  " U [        U5      [        U5      45      n U[        U5      -  n	U[        U5      -  n
X	U
44$ ) r   r   r   r   s              r   resize_image_minr   1   s    hhGA!HHl#h.l#h.8#$H8#$HJ%)j8:EH%)j8:EH	BXH6	7Bq!Gq!G!!!r   c                 \   U R                   u  p#nUnUnSnX'-  U:  a  [        U5      U-  n[        Xg-  5      n[        XW-  5      nSnXh-   S-
  U-  U-  nXX-   S-
  U-  U-  n[        R                  " U [        U5      [        U5      45      n U[        U5      -  n	U[        U5      -  n
X	U
44$ )r   g      ?r   r   r   r   s              r   resize_image_for_totaltextr   I   s    hhGA!HHEy<l#h.8#$H8#$HJ%)j8:EH%)j8:EH	BXH6	7Bq!Gq!G!!!r   c                    / nU  H<  n[         R                  R                  US   US   -
  5      nUR                  U5        M>     [         R                  " U5      nUR                  5       UR                  5       UR                  5       4n[        U 5      S-  nS/U-  n[        U 5       H  u  prUS   Xg'   US   XeS-
  U-
  '   M     [         R                  " U5      R                  SS5      U4$ )z=
Transfer vertical point_pairs into poly point in clockwise.
r   r      )nplinalgnormappendarraymaxminmeanlen	enumeratereshape)point_pair_listpair_length_list
point_pairpair_length	pair_info	point_num
point_listidxs           r   point_pair2polyr6   _   s     %
iinnZ]Z]%BC, & xx 01I O$q(IyJ$_5$Q-
*4Q-
q=3&' 6 88J''A.	99r   c                     [         R                  " U/U//[         R                  S9nU S   U S   U S   -
  U-  -   nU S   U S   U S   -
  U-  -   n[         R                  " US   US   US   US   /5      $ )z#
Generate shrink_quad_along_width.
dtyper   r      r!   )r#   r'   float32)quadbegin_width_ratioend_width_ratio
ratio_pairp0_1p3_2s         r   shrink_quad_along_widthrB   v   s     -.0AB"**UJ7d1gQ':55D7d1gQ':55D88T!Wd1gtAwQ899r   c                    U R                   S   n[        R                  " U S   U S   U S   U S   /[        R                  S9nU* [        R                  R                  US   US   -
  5      -  [        R                  R                  US   US   -
  5      S-   -  n[        X4S5      n[        R                  " XS	-  S	-
     XS	-  S-
     XS	-     XS	-  S-      /[        R                  S9nSU[        R                  R                  US   US   -
  5      -  [        R                  R                  US   US   -
  5      S-   -  -   n[        US
U5      nUS   U S'   US   U S'   US   XS	-  S-
  '   US	   XS	-  '   U $ )z
expand poly along width.
r   r   r"   r8   r:   gư>      ?r!           )r   r#   r'   r;   r$   r%   rB   )	polyshrink_ratio_of_widthr3   	left_quad
left_ratioleft_quad_expand
right_quadright_ratioright_quad_expands	            r   expand_poly_along_widthrO      s    

1I$q'47DHd2h?rzzRI	
))..1	!4
5	699>>)A,156=	? 
 /ycJa!#$a!#$a a!#$		
 jjJ -		1
1%1 	
1
15	6	=? ?K 0
CMq!DG#DH03Da!	,Q/DaKr   c                     U(       a,  [         R                  " [         R                  " U S-  US95      $ [         R                  " [         R                  " U S-  5      5      $ )Nr!   )axis)r#   sqrtsum)xrQ   s     r   norm2rU      s>    wwrvvad.//77266!Q$<  r   c                 V    X-  R                  5       [        U 5      [        U5      -  -  $ N)rS   rU   )p1p2s     r   cosrZ      s"    G==?eBi%)344r   )i   )rF   rE   )g333333?rW   )numpyr#   r
   timer   r   r   r6   rB   rO   rU   rZ    r   r   <module>r^      s9     
 "<"0",:.:@!5r   