§
    ­¸j7  ã                  ót   — d Z ddlmZ ddlmZ ddlmZ ddlZddl	m
Z
 ddlmZ dd„Zddœdd„Zdddœdd„ZdS )zIPrivate keypoint visualization helpers for RF-DETR demos and diagnostics.é    )Úannotations)ÚPath)ÚAnyN)Ú	KeyPoints)Ú&precision_cholesky_to_pixel_covarianceÚ
key_pointsr   Úreturnc           
     ó~  — t          | j                             ¦   «         | j        �| j                             ¦   «         nd| j        �| j                             ¦   «         nd| j        �| j                             ¦   «         nd| j        �| j                             ¦   «         ndt          | j        ¦  «        ¬¦  «        S )z<Return a mutable copy of a Supervision ``KeyPoints`` object.N)ÚxyÚkeypoint_confidenceÚdetection_confidenceÚvisibleÚclass_idÚdata)	r   r   Úcopyr   r   r   r   Údictr   )r   s    új/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/rfdetr/visualize/keypoints.pyÚ_copy_key_pointsr      sº   € åØŒ=×ÒÑÔà5?Ô5SÐ5_ˆJÔ*×/Ò/Ñ1Ô1Ð1Ðeið 7AÔ6UÐ6aˆJÔ+×0Ò0Ñ2Ô2Ð2Ðgkà-7Ô-?Ð-K�
Ô"×'Ò'Ñ)Ô)Ð)ÐQUØ/9Ô/BÐ/N�Ô$×)Ò)Ñ+Ô+Ð+ÐTXÝ�*”/Ñ"Ô"ðñ ô ð ó    g        )Úkeypoint_thresholdr   Úfloatc               óf  — t          | ¦  «        } t          | ¦  «        dk    r| S | j        }|€t          d¦  «        ‚| j                             d¦  «        }| j                             d¦  «        }d| j        vrœ|�š|�˜t          j        |t          j        ¬¦  «        }t          j        |t          j        ¬¦  «        }|j	        dd…         | j
        j	        dd…         k    r3|j	        t          | ¦  «        dfk    rt          ||¬	¦  «        | j        d<   ||k    }| j        }|€|n||z  | _        | S )
aÍ  Build ``KeyPoints`` for visualization from RF-DETR keypoint predictions.

    Args:
        key_points: RF-DETR keypoint prediction output.
        keypoint_threshold: Per-keypoint confidence threshold used to hide
            low-confidence points through ``key_points.visible``.

    Returns:
        A Supervision ``KeyPoints`` object ready for keypoint annotators.

    Raises:
        ValueError: If keypoints are present without per-point confidence.
    r   Nz>Expected RF-DETR keypoints to include per-keypoint confidence.Úkeypoint_precision_choleskyÚsource_shapeÚ
covariance)Údtypeé   )Úprecision_choleskyr   )r   Úlenr   Ú
ValueErrorr   ÚgetÚnpÚasarrayÚfloat32Úshaper   r   r   )	r   r   r   Úraw_precisionÚraw_source_shapeÚ	precisionr   r   Úexisting_visibles	            r   Ú_key_points_for_displayr*   #   sM  € õ$ " *Ñ-Ô-€Jå
ˆ:�„˜!ÒÐØÐØ$Ô8ÐØÐ"ÝÐYÑZÔZÐZà”O×'Ò'Ð(EÑFÔF€MØ!”×*Ò*¨>Ñ:Ô:ÐØ˜:œ?Ð*Ð*¨}Ð/HÐM]ÐMiÝ”J˜}µB´JÐ?Ñ?Ô?ˆ	Ý”zÐ"2½"¼*ÐEÑEÔEˆØŒ?˜2˜A˜2Ô *¤-Ô"5°b°q°bÔ"9Ò9Ð9¸lÔ>PÕUXÐYcÑUdÔUdÐfgÐThÒ>hÐ>hÝ,RØ#,Ø)ð-ñ -ô -ˆJŒO˜LÑ)ð
 "Ð%7Ò7€GØ!Ô)ÐØ$4Ð$<˜˜ÐBRÐU\ÑB\€JÔØÐr   )Úimager   r+   ústr | Path | Noneúlist[dict[str, Any]]c               ó$  — | j         }|€g S |�t          |¦  «        j        nd}| j        }|�|n||k    }| j        }| j                             d¦  «        }g }	t          | j        ¦  «        D �]"\  }
}t          t          |||
         ||
         d¬¦  «        ¦  «        D ]ï\  }\  }}}|rt          j        |d¦  «        rŒ!d}t          |t          j        ¦  «        r(|
t          |¦  «        k     rt          ||
         ¦  «        }|	                     ||
| j        �t%          | j        |
         ¦  «        nd||�t'          ||
         ¦  «        nd|t'          |d         ¦  «        t'          |d         ¦  «        t'          |¦  «        dœ	¦  «         Œð�Œ$|	S )aà  Build flat keypoint prediction rows for notebook or terminal display.

    Args:
        key_points: RF-DETR keypoint prediction output.
        image: Optional image identifier added to each output row. Paths are
            represented by their file name.
        keypoint_threshold: Per-keypoint confidence threshold used when
            ``key_points.visible`` is not already populated.

    Returns:
        A list of row dictionaries, one per visible/non-zero keypoint.
    NÚ
class_nameT)Ústrictr   é   )	r+   Údetection_indexr   r/   r   Úkeypoint_indexÚxÚyr   )r   r   Únamer   r   r   r!   Ú	enumerater   Úzipr"   ÚallcloseÚ
isinstanceÚndarrayr   ÚstrÚappendr   Úintr   )r   r+   r   r   Ú
image_namer)   r   r   Úclass_namesÚrecordsr2   r   r3   ÚpointÚ
confidenceÚ
is_visibler/   s                    r   Ú_keypoint_prediction_recordsrE   N   sÔ  € ð$ %Ô8ÐØÐ"Øˆ	à%*Ð%6•�e‘”Ô!Ð!¸D€JØ!Ô)ÐØ"2Ð">ÐÐÐDWÐ[mÒDm€GØ%Ô:ÐØ”/×%Ò% lÑ3Ô3€KØ$&€GÝ(¨¬Ñ7Ô7ð ñ Ñˆ˜Ý?HÝ�Ð'¨Ô8¸'À/Ô:RÐ[_Ð`Ñ`Ô`ñ@
ô @
ð 	ð 	Ñ;ˆNÑ;˜U J°
ð ð ¥¤¨U°AÑ!6Ô!6ð ØØˆJÝ˜+¥r¤zÑ2Ô2ð ?°ÍÈ[ÑIYÔIYÒ7YÐ7YÝ  ¨_Ô!=Ñ>Ô>�
Ø�NŠNà'Ø'6ØMWÔM`ÐMl¥ JÔ$7¸Ô$HÑ IÔ IÐ IÐrvØ",àH\ÐHh�Ð2°?ÔCÑDÔDÐDÐnrà&4Ý˜u Qœx™œÝ˜u Qœx™œÝ+0°Ñ+<Ô+<ðð ñô ð ð ñ	ð. €Nr   )r   r   r	   r   )r   r   r   r   r	   r   )r   r   r+   r,   r   r   r	   r-   )Ú__doc__Ú
__future__r   Úpathlibr   Útypingr   Únumpyr"   Úsupervisionr   Úrfdetr.utilities.keypointsr   r   r*   rE   © r   r   ú<module>rN      sÜ   ðð PÐ Oà "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ø !Ð !Ð !Ð !Ð !Ð !à MÐ MÐ MÐ MÐ MÐ Mðð ð ð ð& !$ð(ð (ð (ð (ð (ð (ð\  $Ø #ð	4ð 4ð 4ð 4ð 4ð 4ð 4ð 4r   