
    ^j                        d dl mZ d dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ 	 d	 	 	 	 	 	 	 d	dZ	 	 	 d
	 	 	 	 	 	 	 	 	 	 	 ddZy)    )annotationsN)Image)	ImageType)pillow_to_cv2c                   t        | t        j                        rt        |       } t        j                  |       | j
                  dk(  rt        j                  | |       n7t        j                  t        j                  | t        j                               t        j                  d       t        j                          y)a  
    Plots image using matplotlib.

    Args:
        image: The frame to be displayed ImageType
             is a flexible type, accepting either `numpy.ndarray` or `PIL.Image.Image`.
        size: The size of the plot in inches.
        cmap: the colormap to use for single channel images.

    Examples:
        ```pycon
        >>> import cv2
        >>> import numpy as np
        >>> import matplotlib
        >>> matplotlib.use('Agg')  # Prevents the GUI window from popping up
        >>> import supervision as sv
        >>> image = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> sv.plot_image(image=image, size=(16, 16))
        ...

        ```
    )figsize   cmapoffN)
isinstancer   r   pltfigurendimimshowcv2cvtColorCOLOR_BGR2RGBaxisshow)imagesizer   s      e/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/utils/notebook.py
plot_imager      sr    2 %%e$JJtzzQ

5t$

3<<s'8'89:HHUOHHJ    c                   |\  }}t        |       D ].  \  }}t        |t        j                        s!t        |      | |<   0 t	        |       ||z  kD  rt        d      t        j                  |||      \  }	}
t        |
j                        D ]  \  }}|t	        |       k  r| |   j                  dk(  r|j                  | |   |       n6|j                  t        j                  | |   t        j                               |"|t	        |      k  r|j                  ||          |j                  d        t        j                           y)a  
    Plots images in a grid using matplotlib.

    Args:
       images: A list of images as ImageType
             is a flexible type, accepting either `numpy.ndarray` or `PIL.Image.Image`.
       grid_size: A tuple specifying the number
            of rows and columns for the grid.
       titles: A list of titles for each image.
            Defaults to None.
       size: A tuple specifying the width and
            height of the entire plot in inches.
       cmap: the colormap to use for single channel images.

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

    Examples:
        ```pycon
        >>> import cv2
        >>> import numpy as np
        >>> import matplotlib
        >>> matplotlib.use('Agg')  # Prevents the GUI window from popping up
        >>> import supervision as sv
        >>> from PIL import Image
        >>> image1 = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> image2 = Image.new('RGB', (100, 100))
        >>> image3 = np.zeros((100, 100, 3), dtype=np.uint8)
        >>> images = [image1, image2, image3]
        >>> titles = ["Image 1", "Image 2", "Image 3"]
        >>> sv.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   )	enumerater   r   r   len
ValueErrorr   subplotsflatr   r   r   r   r   	set_titler   r   )images	grid_sizetitlesr   r   r   r   idximg_figaxesaxs               r   plot_images_gridr-   2   s$   T LE5f% -Sc5;;'',F3K- 6{UU]"/
 	

 EEJD$TYY' 
RVc{1$		&+D	1		#,,vc{C4E4EFG!cCK&7VC[)

 HHJr   )   r/   gray)r   r   r   tuple[int, int]r   
str | NonereturnNone)Nr.   r0   )r%   zlist[ImageType]r&   r1   r'   zlist[str] | Noner   r1   r   r2   r3   r4   )
__future__r   r   matplotlib.pyplotpyplotr   PILr   supervision.draw.baser   supervision.utils.conversionr   r   r-    r   r   <module>r<      s    " 
   + 6 LR$$+$>H$	$T  $$CCC C 	C
 C 
Cr   