o
    0j                     @   s@   d dl mZmZmZ d dlZddlmZ ejG dd dZ	dS )    )ListTupleUnionN   )	benchmarkc                       s   e Zd ZdZddeeedf f fddZdeee	j
ee	j
df f  dee	j
 fd	d
Zdee	j
ee	j
df f de	j
fddZ  ZS )DocTrPostProcessa^  
    Post-processing class for cropping regions from images (though currently only performs scaling and color channel adjustments).

    Attributes:
        scale (np.float32): A scaling factor to be applied to the image pixel values.
            Defaults to 255.0 if not provided.

    Methods:
        __call__(imgs: List[Union[np.ndarray, Tuple[np.ndarray, ...]]]) -> List[np.ndarray]:
            Call method to process a list of images.
        doctr(pred: Union[np.ndarray, Tuple[np.ndarray, ...]]) -> np.ndarray:
            Method to process a single image or a tuple/list containing an image.
    Nscalec                    s8   t    t|ttfrt|| _dS td| _dS )a  
        Initializes the DocTrPostProcess class with a scaling factor.

        Args:
            scale (Union[str, float, None]): A scaling factor for the image pixel values.
                If a string is provided, it will be converted to a float. Defaults to 255.0.
        g     o@N)super__init__
isinstancestrfloatnpZfloat32r   )selfr   	__class__ t/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/models/image_unwarping/processors.pyr
   &   s
   
zDocTrPostProcess.__init__imgs.returnc                    s    fdd|D S )aW  
        Processes a list of images using the `doctr` method.

        Args:
            imgs (List[Union[np.ndarray, Tuple[np.ndarray, ...]]]): A list of images to process.
                Each image can be a numpy array or a tuple containing a numpy array.

        Returns:
            List[np.ndarray]: A list of processed images.
        c                    s   g | ]}  |qS r   )doctr).0Zimgr   r   r   
<listcomp>@   s    z-DocTrPostProcess.__call__.<locals>.<listcomp>r   )r   r   r   r   r   __call__3   s   zDocTrPostProcess.__call__predc                 C   s|   t |tr
|d }n|}t |tjsJ d|d}|ddd}|| j9 }|dddddddf }|jddd	}|S )
a  
        Processes a single image.

        Args:
            pred (Union[np.ndarray, Tuple[np.ndarray, ...]]): The image to process, which can be
                a numpy array or a tuple containing a numpy array. Only the first element is used if it's a tuple.

        Returns:
            np.ndarray: The processed image.

        Raises:
            AssertionError: If the input is not a numpy array.
        r   z?Invalid input 'im' in DocTrPostProcess. Expected a numpy array.      NZuint8F)copy)r   tupler   ndarrayZsqueezeZ	transposer   Zastype)r   r   Zimr   r   r   r   B   s   



zDocTrPostProcess.doctr)N)__name__
__module____qualname____doc__r   r   r   r
   r   r   r!   r   r   r   __classcell__r   r   r   r   r      s    
0r   )
typingr   r   r   numpyr   Zutils.benchmarkr   Ztimeitr   r   r   r   r   <module>   s
   