
    Wpf                         d Z ddlZddlmZmZmZ ddlmZ ddlmZ ddl	m
Z ddl	mZ ddl	mZ dd	lmZ ej        Zej        Zej        Zej         G d
 d                      Zej         G d d                      ZdS )zDetections data class.    N)AnyListOptional)detection_pb2)location_data_pb2)bounding_box)category)keypoint)doc_controlsc                       e Zd ZU dZej        ed<   eej	                 ed<   dZ
eeej                          ed<   ej        defd            Zeej        dedd fd	                        Zd
edefdZdS )	DetectionzRepresents one detected object in the object detector's results.

  Attributes:
    bounding_box: A BoundingBox object.
    categories: A list of Category objects.
    keypoints: A list of NormalizedKeypoint objects.
  r   
categoriesN	keypointsreturnc                    g }g }g }g }g }| j         D ]}|                    |j                   |j        r|                    |j                   |j        r|                    |j                   |j        r|                    |j                   | j        r| j        D ]|}t                                          }|j	        r|j	        |_	        |j
        r|j
        |_
        |j        r|j        |_        |j        r|j        |_        |                    |           }t          ||||t          t          j        j        | j                                        |                    S )z&Generates a Detection protobuf object.)formatr   relative_keypoints)labellabel_idscoredisplay_namelocation_data)r   appendr   indexcategory_namer   r   _LocationDataProtoRelativeKeypointxyr   keypoint_label_DetectionProtoFormatBOUNDING_BOXr   to_pb2)	selflabels	label_idsscoresdisplay_namesr   r	   r
   relative_keypoint_protos	            w/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/mediapipe/tasks/python/components/containers/detections.pyr$   zDetection.to_pb2-   s    FIFMO 4 4mmHN###	 )(((		 .h,---		 4X2333~ ;n 
; 
;("4"E"E"G"G: 	1&.j
!
#: 	1&.j
!
#> 	B3;>
!
0> 	9*2.
!
'!!"9::::"(%,9*11331
 
 

 
 
 
    pb2_objc                    g }g }t          |j                  D ]\  }}|                    t          j        ||t          |j                  k     r|j        |         nd|t          |j                  k     r|j        |         nd|t          |j                  k     r|j        |         nd                     |j	        j
        r^t          |j	        j
                  D ]D\  }}|                    t          j        |j        |j        |j        |j                             Et!          t"          j                            |j	        j                  ||          S )z<Creates a `Detection` object from the given protobuf object.N)r   r   r   r   )r   r   r   r   )r   r   r   )	enumerater   r   category_moduleCategorylenr   r   r   r   r   keypoint_moduleNormalizedKeypointr   r   r    r   bounding_box_moduleBoundingBoxcreate_from_pb2r   )clsr-   r   r   idxr   elems          r+   r7   zDetection.create_from_pb2X   s    JI..  
U

"s7+,,,, $S))s7=)))) $M#..s7/0000 #/44      / 	
 !6!IJJ 
 
)#t.&&)j	  	
 	
 	
 	
 (4DD!.
 
    r,   otherc                     t          |t                    sdS |                                                     |                                          S zChecks if this object is equal to the given object.

    Args:
      other: The object to be compared with.

    Returns:
      True if the objects are equal.
    F)
isinstancer   r$   __eq__r%   r;   s     r+   r?   zDetection.__eq__   s?     eY'' U;;==///r,   )__name__
__module____qualname____doc__r5   r6   __annotations__r   r0   r1   r   r   r3   r4   r   do_not_generate_docsr!   r$   classmethodr7   r   boolr?    r,   r+   r   r      s           $////?+,,,,BF)Xd?=>?FFF$(o ( ( ( %$(T $&O & & & & %$ ;&P0# 0$ 0 0 0 0 0 0r,   r   c                       e Zd ZU dZee         ed<   ej        de	fd            Z
eej        de	dd fd                        ZdedefdZd	S )
DetectionResultziRepresents the list of detected objects.

  Attributes:
    detections: A list of `Detection` objects.
  
detectionsr   c                 @    t          d | j        D                       S )z*Generates a DetectionList protobuf object.c                 6    g | ]}|                                 S rI   )r$   .0	detections     r+   
<listcomp>z*DetectionResult.to_pb2.<locals>.<listcomp>   s$    GGG)9##%%GGGr,   )rQ   )_DetectionListProtorL   )r%   s    r+   r$   zDetectionResult.to_pb2   s2     GGtGGGI I I Ir,   r-   c                 @    t          d |j        D                       S )zBCreates a `DetectionResult` object from the given protobuf object.c                 B    g | ]}t                               |          S rI   )r   r7   rO   s     r+   rR   z3DetectionResult.create_from_pb2.<locals>.<listcomp>   s3     ' ' '1:	!!),,' ' 'r,   )rL   )rK   rQ   )r8   r-   s     r+   r7   zDetectionResult.create_from_pb2   s:      ' '>E>O' ' '    r,   r;   c                     t          |t                    sdS |                                                     |                                          S r=   )r>   rK   r$   r?   r@   s     r+   r?   zDetectionResult.__eq__   s?     e_-- U;;==///r,   N)rA   rB   rC   rD   r   r   rE   r   rF   rS   r$   rG   r7   r   rH   r?   rI   r,   r+   rK   rK      s           9o$I) I I I %$I
 $$7 <M    %$ ;0# 0$ 0 0 0 0 0 0r,   rK   )rD   dataclassestypingr   r   r   mediapipe.framework.formatsr   r   ,mediapipe.tasks.python.components.containersr   r5   r	   r0   r
   r3   1mediapipe.tasks.python.core.optional_dependenciesr   DetectionListrS   r   r!   LocationDatar   	dataclassrK   rI   r,   r+   <module>r_      s@         & & & & & & & & & & 5 5 5 5 5 5 9 9 9 9 9 9 \ \ \ \ \ \ T T T T T T T T T T T T J J J J J J#1 )&3  n0 n0 n0 n0 n0 n0 n0 n0b #0 #0 #0 #0 #0 #0 #0 #0 #0 #0r,   