o
    eJ                     @   s   d dl mZmZmZ d dlZd dlmZ d dlZ		dde	j
deeef dee ddfd	d
Z			ddee	j
 deeef deee  deeef dee ddfddZdS )    )ListOptionalTupleN   r   grayimagesizecmapreturnc                 C   sP   t j|d | jdkrt j| |d n
t t| tj t d t   dS )a  
    Plots image using matplotlib.

    Args:
        image (np.ndarray): The frame to be displayed.
        size (Tuple[int, int]): The size of the plot.
        cmap (str): the colormap to use for single channel images.

    Examples:
        ```python
        >>> import cv2
        >>> import supervision as sv

        >>> image = cv2.imread("path/to/image.jpg")

        %matplotlib inline
        >>> sv.plot_image(image=image, size=(16, 16))
        ```
    )figsize   r
   offN)	pltfigurendimimshowcv2cvtColorCOLOR_BGR2RGBaxisshow)r   r	   r
    r   I/var/www/myenv/lib/python3.10/site-packages/supervision/utils/notebook.py
plot_image   s   

r   images	grid_sizetitlesc                 C   s   |\}}t | || krtdtj|||d\}}t|jD ]=\}	}
|	t | k rW| |	 jdkr:|
j| |	 |d n|
t	| |	 tj
 |durW|	t |k rW|
||	  |
d qt  dS )a:  
    Plots images in a grid using matplotlib.

    Args:
       images (List[np.ndarray]): A list of images as numpy arrays.
       grid_size (Tuple[int, int]): A tuple specifying the number
            of rows and columns for the grid.
       titles (Optional[List[str]]): A list of titles for each image.
            Defaults to None.
       size (Tuple[int, int]): A tuple specifying the width and
            height of the entire plot in inches.
       cmap (str): the colormap to use for single channel images.

    Raises:
       ValueError: If the number of images exceeds the grid size.

    Examples:
        ```python
        >>> import cv2
        >>> import supervision as sv

        >>> image1 = cv2.imread("path/to/image1.jpg")
        >>> image2 = cv2.imread("path/to/image2.jpg")
        >>> image3 = cv2.imread("path/to/image3.jpg")

        >>> images = [image1, image2, image3]
        >>> titles = ["Image 1", "Image 2", "Image 3"]

        %matplotlib inline
        >>> plot_images_grid(images, grid_size=(2, 2), titles=titles, size=(16, 16))
        ```
    ziThe number of images exceeds the grid size. Please increase the grid size or reduce the number of images.)nrowsncolsr   r   r   Nr   )len
ValueErrorr   subplots	enumerateflatr   r   r   r   r   	set_titler   r   )r   r   r   r	   r
   r   r    figaxesidxaxr   r   r   plot_images_grid)   s   'r+   )r   r   )Nr   r   )typingr   r   r   r   matplotlib.pyplotpyplotr   numpynpndarrayintstrr   r+   r   r   r   r   <module>   s<    

$


