
    ^j                     0   d dl Z d dlmZ d dlmZmZmZ d dlZd dlZ	d dl
mZ d dlmZmZ d dlmZ d dlmZ  ededef   	      Zd
edefdZ eedd      d
edefd       ZdedefdZd
edefdZ eedd      d
edefd       Z eedd      dedefd       Zdee   deej6                  e	j8                        fdZdej                   dej6                  e	j8                     fdZdej6                  e	j8                     dej                   fdZy)    N)Callable)AnyTypeVarcast)
deprecatedvoid)Image)	ImageTypeF.)boundannotate_funcreturnc                      t        j                         dt        dt        dt        dt        dt        f
 fd       }t	        t
        |      S )z
    Decorates `BaseAnnotator.annotate` implementations, converts scene to
    an image type used internally by the annotators, converts back when annotation
    is complete.

    Assumes the annotators modify the scene in-place.
    selfsceneargskwargsr   c                    t        |t        j                        r | |g|i |S t        |t        j                        r4t	        |      } | |g|i |}|j                  t        |             |S t        dt        |             NzUnsupported image type: )	
isinstancenpndarrayr	   pillow_to_cv2pastecv2_to_pillow
ValueErrortype)r   r   r   r   scene_npannotated_npr   s         g/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/supervision/utils/conversion.pywrapperz2ensure_cv2_image_for_class_method.<locals>.wrapper   s    eRZZ( u>t>v>>eU[[)$U+H(xI$I&ILKKl34L3DK=ABB    	functoolswrapsr   r
   r   r   r   r!   s   ` r    !ensure_cv2_image_for_class_methodr'      sY     __]#
Cc 
C) 
CC 
C3 
C9 
C $
C 7r"   z0.27.0z0.31.0)targetdeprecated_in	remove_inc                 4    t        t        t        |             S Nr   r   r   r   s    r    ensure_cv2_image_for_annotationr/   +        4&''r"   image_processing_func           	           t        j                         dt        dt        dt        dt        f fd       }t	        t
        |      S )z
    Decorates image processing functions that accept np.ndarray, converting `image` to
    np.ndarray, converts back when processing is complete.

    Assumes the annotators do NOT modify the scene in-place.
    imager   r   r   c                     t        | t        j                        r | g|i |S t        | t        j                        r"t	        |       } |g|i |}t        |      S t        dt        |              r   )r   r   r   r	   r   r   r   r   )r3   r   r   r   	annotatedr1   s        r    r!   z9ensure_cv2_image_for_standalone_function.<locals>.wrapper@   st    eRZZ('????eU[[)!%(E,UDTDVDI ++3DK=ABBr"   )r$   r%   r
   r   r   r   )r1   r!   s   ` r    (ensure_cv2_image_for_standalone_functionr6   6   sR     __)*	Cy 	C 	C 	C	 	C +	C 7r"   c                      t        j                         dt        dt        dt        dt        dt        f
 fd       }t	        t
        |      S )z
    Decorates image processing functions that accept np.ndarray, converting `image` to
    PIL image, converts back when processing is complete.

    Assumes the annotators modify the scene in-place.
    r   r   r   r   r   c                 B   t        |t        j                        r9t        |      } | |g|i |}t        j                  |t        |             |S t        |t        j                        rt        t         | |g|i |      S t        dt        |             r   )r   r   r   r   copytor   r	   r   r
   r   r   )r   r   r   r   	scene_pilannotated_pilr   s         r    r!   z2ensure_pil_image_for_class_method.<locals>.wrapperY   s    eRZZ(%e,I)$	KDKFKMIIe]=9:LeU[[)	=u#Nt#Nv#NOO3DK=ABBr"   r#   r&   s   ` r    !ensure_pil_image_for_class_methodr<   O   sY     __]#
Cc 
C) 
CC 
C3 
C9 
C $
C 7r"   c                 4    t        t        t        |             S r,   r-   r.   s    r    ensure_pil_image_for_annotationr>   i   r0   r"   c                 4    t        t        t        |             S r,   r-   )r1   s    r    ensure_cv2_image_for_processingr@   t   s     4,-..r"   imagesc                     g }| D ]A  }t        t        |      t        j                        rt        |      }|j	                  |       C |S )z
    Converts images provided either as Pillow images or OpenCV
    images into OpenCV format.

    Args:
        images: Images to be converted

    Returns:
        List of input images in OpenCV format
            (with order preserved).

    )
issubclassr   r	   r   append)rA   resultr3   s      r    images_to_cv2rF      sG     F d5k5;;/!%(Ee Mr"   r3   c                     t        j                  |       }t        j                  |t        j                        }|j                  t         j                  d      S )z
    Converts Pillow image into OpenCV image, handling RGB -> BGR
    conversion.

    Args:
        image: Pillow image (in RGB format).

    Returns:
        Input image converted to OpenCV format.
    F)copy)r   arraycv2cvtColorCOLOR_RGB2BGRastypeuint8)r3   r   s     r    r   r      s@     HHUOELL 1 12E <<u<--r"   c                 t    t        j                  | t         j                        } t        j                  |       S )z
    Converts OpenCV image into Pillow image, handling BGR -> RGB
    conversion.

    Args:
        image: OpenCV image (in BGR format).

    Returns:
        Input image converted to Pillow format.
    )rJ   rK   COLOR_BGR2RGBr	   	fromarray)r3   s    r    r   r      s)     LL 1 12E??5!!r"   ) r$   collections.abcr   typingr   r   r   rJ   numpyr   numpy.typingnpt	deprecater   r   PILr	   supervision.draw.baser
   r   r'   r/   r6   r<   r>   r@   listNDArrayrN   rF   r   r    r"   r    <module>r]      s~    $ % % 
   &  +CxS)*6 ,
(((
(24 ,
(((
( 3
///
/$y/ d3;;rxx3H.I *. .RXX)> .$"RXX. "5;; "r"   