Skip to content

Commit

Permalink
Add soft check to Keypoint msg
Browse files Browse the repository at this point in the history
  • Loading branch information
HonzaCuhel committed Jan 30, 2025
1 parent 8931b1e commit 2e7ddb4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions depthai_nodes/ml/messages/keypoints.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
from typing import List

import depthai as dai

from depthai_nodes.ml.helpers.constants import KEYPOINT_COLOR

logger = logging.getLogger(__name__)


class Keypoint(dai.Buffer):
"""Keypoint class for storing a keypoint.
Expand Down Expand Up @@ -48,8 +51,11 @@ def x(self, value: float):
"""
if not isinstance(value, float):
raise TypeError("x must be a float.")
if value < 0 or value > 1:
if value < -0.1 or value > 1.1:
raise ValueError("x must be between 0 and 1.")
if not (0 <= value <= 1):
value = max(0, min(1, value))
logging.warning("x value was clipped to [0, 1].")
self._x = value

@property
Expand All @@ -72,8 +78,11 @@ def y(self, value: float):
"""
if not isinstance(value, float):
raise TypeError("y must be a float.")
if value < 0 or value > 1:
if value < -0.1 or value > 1.1:
raise ValueError("y must be between 0 and 1.")
if not (0 <= value <= 1):
value = max(0, min(1, value))
logging.warning("y value was clipped to [0, 1].")
self._y = value

@property
Expand Down Expand Up @@ -117,8 +126,11 @@ def confidence(self, value: float):
"""
if not isinstance(value, float):
raise TypeError("confidence must be a float.")
if value < 0 or value > 1:
raise ValueError("confidence must be between 0 and 1.")
if value < -0.1 or value > 1.1:
raise ValueError("Confidence must be between 0 and 1.")
if not (0 <= value <= 1):
value = max(0, min(1, value))
logging.warning("Confidence value was clipped to [0, 1].")
self._confidence = value


Expand Down

0 comments on commit 2e7ddb4

Please sign in to comment.