
    9i!                     b    S SK r S SKJr  S SKrS SKJrJr  SSKJ	r	J
r
JrJr   " S S\	\
\5      rg)    N)Dict)Image	ImageDraw   )BaseCVResult	HtmlMixin	JsonMixin	XlsxMixinc                      ^  \ rS rSrSrSU 4S jjrS\\\R                  4   4S jr
S\\\4   4S jrS\\\4   4S jrS\\\4   4S jrS\\\4   4S	 jrS
rU =r$ )LayoutParsingResult   zLayout Parsing Resultreturnc                 |   > [         TU ]  U5        [        R                  " U 5        [        R                  " U 5        g)z@Initializes a new instance of the class with the specified data.N)super__init__r   r
   )selfdata	__class__s     q/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/inference/pipelines/layout_parsing/result.pyr   LayoutParsingResult.__init__   s,    4 4     c           
         0 nU S   nUS   (       a  UR                   " S0 U S   R                  D6  U S   R                  S   US'   U S   R                  S   US'   US   (       a  [        U S	   5      S
:  a  [        R                  " [
        R                  " U S   S   S S 2S S 2S S S24   5      5      n[        R                  " U5      nSn[        [        U S	   5      5       HK  nU S	   U   nUS   nU H5  n	U	 V
s/ s H  n
[        U
5      PM     sn
u  ppUR                  XX/USS9  M7     MM     X1S'   US   (       aV  [        U S   5      S
:  aD  [        [        U S   5      5       H)  nU S   U   nUS   nUR                  nSU 3nUS   UU'   M+     US   (       aV  [        U S   5      S
:  aD  [        [        U S   5      5       H)  nU S   U   nUS   nUR                  nSU 3nUS   UU'   M+     U$ s  sn
f )Nmodel_settingsuse_doc_preprocessordoc_preprocessor_reslayout_det_resresoverall_ocr_resocr_res_imguse_table_recognitiontable_res_listr   
output_img)   r   r   cell_box_list   )outlinewidthtable_cell_imguse_seal_recognitionseal_res_listseal_region_idseal_res_regionuse_formula_recognitionformula_res_listformula_region_idformula_res_region )updateimglenr   	fromarraycopydeepcopyr   Drawrangeint	rectangle)r   res_img_dictr   r)   
table_drawrectangle_colorsno	table_resr%   boxposx1y1x2y2seal_resr,   sub_seal_res_dictkeyformula_resr0   sub_formula_res_dicts                         r   _to_imgLayoutParsingResult._to_img!   sV   ./01C$'=">"B"BC)-.>)?)C)CE)J%&*./@*A*E*Em*T&'12s4@P;Q7RUV7V"__d#9:<HAtQStTUN #7J)OS&6!789 !1237	 )/ :(C:=%>#3c#h#%>NBB(((/ )  ) : .<)*01c$:O6PST6TSo!67805!)*:!;$,LL!''78$5m$DS! 9 45D+,-1S&8!9:;"#56s;$/0C$D!'2$*+<*=>$8$?S! < 3 &?s   <G8c                    0 nU S   US'   U S   US'   U S   nXCS'   U S   US'   U S   S   (       a  U S   R                   S   US'   U S   R                   S   US'   U S	   R                   S   US	'   US
   (       a^  [        U S   5      S:  aL  / US'   [        [        U S   5      5       H,  nU S   U   nUS   R                  UR                   S   5        M.     US   (       a^  [        U S   5      S:  aL  / US'   [        [        U S   5      5       H,  nU S   U   nUS   R                  UR                   S   5        M.     US   (       a^  [        U S   5      S:  aL  / US'   [        [        U S   5      5       H,  nU S   U   nUS   R                  UR                   S   5        M.     [        R
                  " U/UQ70 UD6$ )aH  Converts the instance's attributes to a dictionary and then to a string.

Args:
    *args: Additional positional arguments passed to the base class method.
    **kwargs: Additional keyword arguments passed to the base class method.

Returns:
    Dict[str, str]: A dictionary with the instance's attributes converted to strings.

input_path
page_indexr   parsing_res_listr   r   r   r   r   r    r!   r   r*   r+   r.   r/   )strr5   r:   appendr	   _to_str	r   argskwargsr   r   r@   rA   rH   rK   s	            r   rU   LayoutParsingResult._to_strO   s    !,/\!,/\./!/#'(:#;  !"89+/0F+G+K+KE+RD'(!%&6!7!;!;E!B"&'8"9"="=e"D12s4@P;Q7RUV7V%'D!"S&6!789 !1237	%&--immE.BC : 01c$:O6PST6T$&D!So!67805_%,,X\\%-@A 9 45D+,-1')D#$S&8!9:;"#56s;'(//0FG <   7777r   c                    0 nU S   US'   U S   US'   U S   nXCS'   U S   US'   U S   S   (       a  U S   R                   S   US'   U S   R                   S   US'   U S	   R                   S   US	'   US
   (       a^  [        U S   5      S:  aL  / US'   [        [        U S   5      5       H,  nU S   U   nUS   R                  UR                   S   5        M.     US   (       a^  [        U S   5      S:  aL  / US'   [        [        U S   5      5       H,  nU S   U   nUS   R                  UR                   S   5        M.     US   (       a^  [        U S   5      S:  aL  / US'   [        [        U S   5      5       H,  nU S   U   nUS   R                  UR                   S   5        M.     [        R
                  " U/UQ70 UD6$ )a#  
Converts the object's data to a JSON dictionary.

Args:
    *args: Positional arguments passed to the JsonMixin._to_json method.
    **kwargs: Keyword arguments passed to the JsonMixin._to_json method.

Returns:
    Dict[str, str]: A dictionary containing the object's data in JSON format.
rP   rQ   r   rR   r   r   r   r   r   r    r!   r   r*   r+   r.   r/   )jsonr5   r:   rT   r	   _to_jsonrV   s	            r   r\   LayoutParsingResult._to_jsonx   s    !,/\!,/\./!/#'(:#;  !"89+/0F+G+L+LU+SD'(!%&6!7!<!<U!C"&'8"9">">u"E12s4@P;Q7RUV7V%'D!"S&6!789 !1237	%&--innU.CD : 01c$:O6PST6T$&D!So!67805_%,,X]]5-AB 9 45D+,-1')D#$S&8!9:;"#56s;'(//0@0@0GH < !!$8888r   c                     U S   n0 nUS   (       aS  [        U S   5      S:  aA  [        [        U S   5      5       H&  nU S   U   nUS   nSU 3nUR                  S   X&'   M(     U$ )zConverts the prediction to its corresponding HTML representation.

Returns:
    Dict[str, str]: The str type HTML representation result.
r   r    r!   r   table_region_idtable_pred)r5   r:   html)r   r   res_html_dictr@   rA   r_   rJ   s          r   _to_htmlLayoutParsingResult._to_html        ./12s4@P;Q7RUV7VS&6!789 !1237	"+,=">/0%.^^F%;"	 :
 r   c                     U S   n0 nUS   (       aS  [        U S   5      S:  aA  [        [        U S   5      5       H&  nU S   U   nUS   nSU 3nUR                  S   X&'   M(     U$ )zzConverts the prediction HTML to an XLSX file path.

Returns:
    Dict[str, str]: The str type XLSX representation result.
r   r    r!   r   r_   r`   ra   )r5   r:   xlsx)r   r   res_xlsx_dictr@   rA   r_   rJ   s          r   _to_xlsxLayoutParsingResult._to_xlsx   rf   r   r2   )r   N)__name__
__module____qualname____firstlineno____doc__r   r   rS   npndarrayrM   rU   r\   rd   rj   __static_attributes____classcell__)r   s   @r   r   r      s|    !,c2::o. ,\'8$sCx. '8R'94S> '9R$sCx.  $sCx.  r   r   )r7   typingr   numpyrq   PILr   r   common.resultr   r   r	   r
   r   r2   r   r   <module>ry      s+         J Jg,	9 gr   