From 5d43e1380d248d2c8db5a3352feea855199d01f6 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Tue, 9 Apr 2024 17:42:31 +0300 Subject: [PATCH] =?UTF-8?q?feat(test):=20=F0=9F=9A=80=20mock=20keypoints?= =?UTF-8?q?=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Onuralp SEZER --- test/test_utils.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test_utils.py b/test/test_utils.py index b8ef9231..d3624845 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -3,6 +3,7 @@ from typing import Any, Dict, List, Optional import numpy as np from supervision.detection.core import Detections +from supervision.keypoints.core import KeyPoints def mock_detections( @@ -30,5 +31,24 @@ def mock_detections( ) +def mock_keypoints( + xy: List[List[float]], + confidence: Optional[List[float]] = None, + class_id: Optional[List[int]] = None, + data: Optional[Dict[str, List[Any]]] = None, +) -> KeyPoints: + def convert_data(data: Dict[str, List[Any]]): + return {k: np.array(v) for k, v in data.items()} + + return KeyPoints( + xy=np.array(xy, dtype=np.float32), + confidence=( + confidence if confidence is None else np.array(confidence, dtype=np.float32) + ), + class_id=(class_id if class_id is None else np.array(class_id, dtype=int)), + data=convert_data(data) if data else {}, + ) + + def assert_almost_equal(actual, expected, tolerance=1e-5): assert abs(actual - expected) < tolerance, f"Expected {expected}, but got {actual}."