o
    0j
                     @   sh   d dl ZddlmZmZ ddlmZ ddlmZ edr d dl	Z	ej
ddd	edG d
d dZdS )    N   )class_requires_depsis_dep_available   )	benchmark)ImageReaderzopencv-contrib-pythonT)nameZis_read_operationc                       s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )
	ReadImagezLoad image from the file.BGRc                    s:   t    || _tjtjtjd| j }td|d| _dS )z
        Initialize the instance.

        Args:
            format (str, optional): Target color format to convert the image to.
                Choices are 'BGR', 'RGB', and 'GRAY'. Default: 'BGR'.
        )r
   RGBZGRAYZopencv)backendflagsN)super__init__formatcv2ZIMREAD_COLORZIMREAD_GRAYSCALEr   _img_reader)selfr   r   	__class__ m/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/paddlex/inference/common/reader/image_reader.pyr      s   
zReadImage.__init__c                    s    fdd|D S )applyc                    s   g | ]}  |qS r   )read).0imgr   r   r   
<listcomp>1   s    z&ReadImage.__call__.<locals>.<listcomp>r   )r   Zimgsr   r   r   __call__/   s   zReadImage.__call__c                 C   s   t |tjr| jdkrt|tj}|S t |trA| j	|}|d u r*t
d| | jdkr?|jdkr8tdt|tj}|S tdt|j d)Nr   zImage read Error: r   zArray is not 3-dimensional.zReadImage only supports the following types:
1. str, indicating a image file path or a directory containing image files.
2. numpy.ndarray.
However, got type: .)
isinstancenpZndarrayr   r   ZcvtColorZCOLOR_BGR2RGBstrr   r   	ExceptionndimRuntimeError	TypeErrortype__name__)r   r   Zblobr   r   r   r   3   s$   



zReadImage.read)r
   )r(   
__module____qualname____doc__r   r   r   __classcell__r   r   r   r   r	      s
    r	   )numpyr!   Z
utils.depsr   r   Zutils.benchmarkr   Zutils.ior   r   Ztimeit_with_optionsr	   r   r   r   r   <module>   s   