o
    'j\                     @   s`   d dl Z d dlZd dlmZmZmZ d dlZd dlm	Z	m
Z
mZmZ dd Zdd Zdd	 ZdS )
    N)Image	ImageDraw	ImageFont)draw_ocr_box_txtstr2boolstr2int_tuple	init_argsc                  C   s  t  } | jdtdd | jdtdd | jdtdd | jdtd	 | jd
tdd | jdtdd | jdtd	 | jdtdd | jdtddd | jdtddd | jdtdd | jdtd	 | jdtd	 | jdtdd | jdtdd | jdtd d | jdtd d!gd d"d# | jd$td%d&d | jd'tdd(d | jd)tdd*d | jd+tdd,d | jd-td%d.d | jd/td%d0d | jd1td%d2d | jd3td%d4d | jd5td6d7d | S )8Nz--outputz./output)typedefaultz--table_max_leni  z--table_algorithmZ	TableAttnz--table_model_dir)r	   z--merge_no_span_structureTz--table_char_dict_pathz/../ppocr/utils/dict/table_structure_dict_ch.txtz--layout_model_dirz--layout_dict_pathz9../ppocr/utils/dict/layout_dict/layout_publaynet_dict.txtz--layout_score_thresholdg      ?zThreshold of score.)r	   r
   helpz--layout_nms_thresholdzThreshold of nms.z--kie_algorithmZ	LayoutXLMz--ser_model_dirz--re_model_dirz--use_visual_backbonez--ser_dict_pathz'../train_data/XFUND/class_list_xfun.txtz--ocr_order_methodz--modeZ	structureZ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--ocrz@In the forward, whether the non-table area is recognition by ocrz
--recoveryz$Whether to enable layout of recoveryz--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   parser r   ^/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddleocr/ppstructure/utility.pyr      s   r   c                  C   s   t  } |  S )N)r   
parse_argsr   r   r   r   r   x   s   r   c                 C   s  t | tjrt| } g g g }}}|  }t|}d}d}	i }
d}tj	||dd}|D ]}|d |
vrNt
ddt
ddt
ddf}||
|d < n|
|d  }|d	 }|j|d |d
 f|d |d fg|dd ||d \}}}}|| || }}|j|d |d
 f|d | |d
 | fg|	d |j|d |d
 f|d ||d |d dkrq.|d D ]}|t|d  ||d  ||d  qq.t|||||dd}|S )Nr   )P      r      zutf-8)encodingr	   r   r   Zbbox         )outlinewidth)fill)r#   fonttableresZtext_regiontextZ
confidence)	font_pathZ
drop_score)
isinstancenpZndarrayr   Z	fromarraycopyr   ZDrawr   ZtruetyperandomrandintZ	rectangleZgetbboxr'   appendarrayr   )imageresultr(   ZboxesZtxtsZscoresZ
img_layoutZdraw_layoutZ
text_colorZtext_background_colorZcatid2colorZ	font_sizer$   regionZ	box_colorZ
box_layoutlefttoprightbottomZtext_wZtext_hZtext_resultZim_showr   r   r   draw_structure_result}   s`   


r7   )r,   astZPILr   r   r   numpyr*   Ztools.infer.utilityr   r   r   r   r   r   r7   r   r   r   r   <module>   s   c