
    i(                     p    S SK r S SKrS SKrS SKJrJrJr  S SKrS SKJ	r	J
r
JrJr  S SKrS rS rS rS rg)    N)Image	ImageDraw	ImageFont)draw_ocr_box_txtstr2boolstr2int_tuple	init_argsc                  r   [        5       n U R                  S[        SS9  U R                  S[        SS9  U R                  S[        SS9  U R                  S[        S	9  U R                  S
[        SS9  U R                  S[        SS9  U R                  S[        SS9  U R                  S[        S	9  U R                  S[        SS9  U R                  S[        SS9  U R                  S[        S	9  U R                  S[        SS9  U R                  S[
        SSS9  U R                  S[
        SSS9  U R                  S[        SS9  U R                  S [        S	9  U R                  S![        S	9  U R                  S"[        SS9  U R                  S#[        S$S9  U R                  S%[        S S9  U R                  S&[        S'S(/S'S)S*9  U R                  S+[        S,S-S9  U R                  S.[        SS/S9  U R                  S0[        SS1S9  U R                  S2[        S,S3S9  U R                  S4[        SS5S9  U R                  S6[        S,S7S9  U R                  S8[        S,S9S9  U R                  S:[        S,S;S9  U R                  S<[        S,S=S9  U R                  S>[        S,S?S9  U R                  S@[        SASBS9  U $ )CNz--outputz./output)typedefaultz--table_max_leni  z--table_algorithm	TableAttnz--table_model_dir)r   z--merge_no_span_structureTz--table_char_dict_pathz/../ppocr/utils/dict/table_structure_dict_ch.txtz--formula_algorithmLaTeXOCRz--formula_model_dirz--formula_char_dict_pathz,../ppocr/utils/dict/latex_ocr_tokenizer.jsonz--formula_batch_num   z--layout_model_dirz--layout_dict_pathz9../ppocr/utils/dict/layout_dict/layout_publaynet_dict.txtz--layout_score_threshold      ?zThreshold of score.)r   r   helpz--layout_nms_thresholdzThreshold of nms.z--kie_algorithm	LayoutXLMz--ser_model_dirz--re_model_dirz--use_visual_backbonez--ser_dict_pathz'../train_data/XFUND/class_list_xfun.txtz--ocr_order_methodz--mode	structurekiezstructure and kie is supported)r   choicesr   r   z--image_orientationFz/Whether to enable image orientation recognitionz--layoutz!Whether to enable layout analysisz--tablez=In the forward, whether the table area uses table recognitionz	--formulaz%Whether to enable formula recognitionz--ocrz@In the forward, whether the non-table area is recognition by ocrz
--recoveryz$Whether to enable layout of recoveryz--recovery_to_markdownz0Whether to enable layout of recovery to markdownz--use_pdf2docx_apizWhether to use pdf2docx apiz--invertz)Whether to invert image before processingz
--binarizez5Whether to threshold binarize image before processingz--alphacolor   r   r   zQReplacement color for the alpha channel, if the latter is present; R,G,B integers)
infer_argsadd_argumentstrintr   floatboolr   parsers    ]/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddleocr/ppstructure/utility.pyr	   r	      s   \F 
jA
)SA
+#{K
+#6
3(DQ
 A   -CL
-C8
">  
 -CC
,37
K  
 "BW    uc@S   )[I
)4
(s3
/hM
-V   ,3E
e$-   >	   0	   L	   4	   O	   3	    ?	   *	   8	   D	   `	   M    c                  6    [        5       n U R                  5       $ )N)r	   
parse_argsr   s    r    r#   r#      s    [Fr!   c                 P   [        U [        R                  5      (       a  [        R                  " U 5      n / / / pTnU R                  5       n[        R                  " U5      nSnSn	0 n
Sn[        R                  " X+SS9nU GH  nUS   U
;  aL  [        R                  " SS5      [        R                  " SS5      [        R                  " SS5      4nXUS   '   OXS      nUS	   nUR                  US   US
   4US   US   4/USS9  [        [        R                  R!                  S5      S   5      S:  a  UR#                  US   5      u  nnO#UR%                  US   5      u  nnnnUU-
  UU-
  nnUR                  US   US
   4US   U-   US
   U-   4/U	S9  UR'                  US   US
   4US   XS9  US   S:X  d  US   S:X  a  SUS   ;   a  GMT  US    GH7  nUR)                  [        R*                  " US   5      5        UR)                  US   5        UR)                  US   5        SU;   d  M\  US    H  nUn[        [,        R.                  " US   S   US   S   -
  S-  US   S
   US   S
   -
  S-  -   5      5      n[        [,        R.                  " US   S   US
   S   -
  S-  US   S
   US
   S
   -
  S-  -   5      5      nUS:X  d  US:X  a  M  UR)                  U5        UR)                  S5        UR)                  S5        M     GM:     GM     [1        XcXEUSS9nU$ )Nr   )P      r      zutf-8)encodingr   r   r   bboxr         )outlinewidth.
   )fill)r0   fonttableequationlatexrestext_regiontext
confidencetext_word_region g      ?)	font_path
drop_score)
isinstancenpndarrayr   	fromarraycopyr   Drawr   truetyperandomrandint	rectangler   PIL__version__splitgetsizegetbboxr7   appendarraymathsqrtr   )imageresultr;   boxestxtsscores
img_layoutdraw_layout
text_colortext_background_colorcatid2color	font_sizer1   region	box_color
box_layouttext_wtext_hlefttoprightbottomtext_resultword_regionchar_box
box_height	box_widthim_shows                               r    draw_structure_resultrj      s{   %$$&b"EJ..,K J*KIiWED&>,q#&q#&q#&I
 +4v'#6N3IF^
mZ]+jmZ]-KL 	 	
 s$$S)!,-2!\\&.9NFF'+||F6N'C$D#uf"T\6C<FFA
1.A'A)?@ ' 	 	
 	]JqM*F6N 	 	
 &>W$6Nj(Wu-E%e}RXXk-&@ABK/0k,78%4'23E'F#.%( II!)!Q(1+a.!@Q F#+A;q>HQKN#Bq"H!I&
 %( II!)!Q(1+a.!@Q F#+A;q>HQKN#Bq"H!I%	 &?i1n$[1Bc*% (G  -O B 49G Nr!   c                    Uu  p4pVUR                  5       nUS   S   nUS   S   nUS   S   n	US   S   n
X-
  U-  n/ n/ n/ n/ n[        XEU5       H  u  nnnUS:X  aN  [        U5      S:w  a3  US   US   -
  S-   U-  nU[        U5      S-
  -  nUR                  U5        UU-  nUU-  nM[  U[	        US   U-  5      -   nU[	        US   S-   U-  5      -   nUU	4UU	4UU
4UU
44nUR                  U5        UR                  SR                  U5      5        M     [        U5      S:w  a  [        U5      S:w  a  [        R                  " U5      nOX-
  [        U 5      -  nU Hh  nUS-   U-  n[        [	        UUS-  -
  5      S5      U-   n[        [	        UUS-  -   5      X-
  5      U-   nUU	4UU	4UU
4UU
44nUR                  U5        Mj     X4$ )zdCalculate the detection frame for each word based on the results of recognition and detection of ocrr   r   r*   cnr:   r   )
tolistziplenrL   r   joinr>   meanmaxmin)rec_strboxrec_word_infocol_num	word_listword_col_list
state_listbbox_x_start
bbox_x_endbbox_y_start
bbox_y_end
cell_widthword_box_listword_box_content_listcn_width_listcn_col_listwordword_colstatechar_seq_length
char_widthcell_x_start
cell_x_endcellavg_char_width
center_idxcenter_xs                              r    cal_ocr_word_boxr      sQ    5B1G
**,Cq6!9LQJq6!9LQJ+w6JMMK!$Yz!JhD=8}!#+B<(1+#=#AZ"O,H0AB
$$Z08#K!T)!'#hqkJ.F*GGL%Xb\A-=,K(LLJ|,\*Z(z*	D   &!((7% "K& ;1}"WW]3N(73w<GN%J"S(J6Hs8nq.@#@A1ETLC>A#556
8QR 
 |,\*Z(z*	D   & & !//r!   )rD   astrG   r   r   r   numpyr>   tools.infer.utilityr   r   r   r	   r   rN   r#   rj   r    r!   r    <module>r      s@     
 
 + +   {|
Qh70r!   