o
    0j                     @   sP   d dl mZ d dlmZmZ ddlmZmZ ddlm	Z	m
Z
 G dd de	Zd	S )
    )Dict)Image	ImageDraw   )PINGFANG_FONTcreate_font   )BaseCVResult	JsonMixinc                   @   sT   e Zd ZdZdeeejf fddZdeeef fddZdeeef fddZ	d	S )
DocPreprocessorResultzdoc preprocessor resultreturnc                 C   s  | d dddddddf }| d dddddddf }| d }| d dddddddf }| d d }| d d	 }|j d
d \}}|j d
d \}	}
|j d
d \}}tt||	|}td||
 | |d fd}|t|d
d
||f |t||d
||
 |	f |t|||
 d
||
 | |f t|}g d}d| d| d|d< d| d|d< ||
|g}d
|||
 g}tt	|D ]"}|| }t
||| dftj}|jd||  |d g|d|d qd|i}|S )z
        Generate an image combining the original, rotated, and unwarping images.

        Returns:
            Dict[Image.Image]: A new image combining the original, rotated, and unwarping images
        Z	input_imgNrot_imgangle
output_imgmodel_settingsuse_doc_orientation_classifyuse_doc_unwarpingr      RGB   )   r   r   )zOriginal ImagezRotated ImagezUnwarping ImagezRotated Image (z, )   zUnwarping Image (   
   )r   r   r   )fillfontZpreprocessed_img)shapemaxr   newZpasteZ	fromarrayr   ZDrawrangelenr   r   pathtext)selfimager   r   r   r   r   Zh1Zw1h2Zw2Zh3Zw3hZimg_showZ	draw_textZtxt_listZregion_w_listZ
beg_w_listZtnotxtr   Zimgs r*   t/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/pipelines/doc_preprocessor/result.py_to_img   s<      &

zDocPreprocessorResult._to_imgc                 O   L   i }| d |d< | d |d< | d |d< | d |d< t j|g|R i |S )ax  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   r   )r
   _to_strr%   argskwargsdatar*   r*   r+   r0   A   s   
zDocPreprocessorResult._to_strc                 O   r-   )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.
        r.   r/   r   r   )r
   _to_jsonr1   r*   r*   r+   r5   R   s   zDocPreprocessorResult._to_jsonN)
__name__
__module____qualname____doc__r   strr   r,   r0   r5   r*   r*   r*   r+   r      s
    'r   N)typingr   ZPILr   r   Zutils.fontsr   r   Zcommon.resultr	   r
   r   r*   r*   r*   r+   <module>   s
   