Ë
    ¼Ó^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ƒ   ø€ ä�eœRŸZ™ZÔ(Ù   uÐ>¨tÒ>°vÑ>Ð>ä�eœUŸ[™[Ô)Ü$ UÓ+ˆHÙ(¨¨xÐI¸$ÒIÀ&ÑIˆLØ�K‰Kœ lÓ3Ô4ØˆLäÐ3´D¸³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   ø€ ä�eœRŸZ™ZÔ(Ù'¨Ð?°Ò?¸Ñ?Ð?ä�eœUŸ[™[Ô)Ü! %Ó(ˆEÙ,¨UÐD°TÒD¸VÑDˆIÜ  Ó+Ð+äÐ3´D¸³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Œ   ø€ ä�eœRŸZ™ZÔ(Ü% eÓ,ˆIÙ)¨$°	ÐK¸DÒKÀFÑKˆMÜ�I‰I�eœ]¨=Ó9Ô:ØˆLä�eœUŸ[™[Ô)Üœ	¡=°°uÐ#N¸tÒ#NÀvÑ#NÓOÐOäÐ3´D¸³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Øò ˆÜ”d˜5“k¤5§;¡;Ô/Ü! %Ó(ˆ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@   € ô �H‰H�U‹O€EÜ�L‰L˜¤× 1Ñ 1Ó2€Eð �<‰<œŸ™ 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)   € ô �L‰L˜¤× 1Ñ 1Ó2€EÜ�?‰?˜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~  ðÛ Ý $ß %Ñ %ã 
Û Ý ß &Ý å +áˆC�x  S Ñ)Ô*€ðØðàóñ6 Ø,ØØôð
(Øð(àò(óð
(ðØðàóð2Øðàóñ4 Ø,ØØôð
(Øð(àò(óð
(ñ Ø3ØØôð
/Øð/àò/óð
/ð˜$˜y™/ð ¨d°3·;±;¸r¿x¹xÑ3HÑ.Ió ð*.˜Ÿ™ð .¨¯©°R·X±XÑ)>ó .ð$"˜Ÿ™ R§X¡XÑ.ð "°5·;±;ô "r"   