Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epytext documentation. #13

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions depthai_nodes/ml/messages/creators/depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ def create_depth_message(
"""Creates a depth message in the form of an ImgFrame using the provided depth map
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
and depth type.

Args:
depth_map (np.array): A NumPy array representing the depth map with shape (CHW or HWC).
depth_type (Literal['relative', 'metric']): A string indicating the type of depth map.
It can either be 'relative' or 'metric'.

Returns:
dai.ImgFrame: An ImgFrame object containing the depth information.
@param depth_map: A NumPy array representing the depth map with shape (CHW or HWC).
@type depth_map: np.array
@param depth_type: A string indicating the type of depth map. It can either be
'relative' or 'metric'.
@type depth_type: Literal['relative', 'metric']
@return: An ImgFrame object containing the depth information.
@rtype: dai.ImgFrame
@raise ValueError: If the depth map is not a NumPy array.
@raise ValueError: If the depth map is not 3D.
@raise ValueError: If the depth map shape is not CHW or HWC.
@raise ValueError: If the depth type is not 'relative' or 'metric'.
"""

if not isinstance(depth_map, np.ndarray):
Expand Down
55 changes: 40 additions & 15 deletions depthai_nodes/ml/messages/creators/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,33 @@ def create_detection_message(
"""Create a message for the detection. The message contains the bounding boxes,
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
labels, and confidence scores of detected objects. If there are no labels or we only
have one class, we can set labels to None and all detections will have label set to
0.

Args:
bboxes (np.ndarray): Detected bounding boxes of shape (N,4) meaning [...,[x_min, y_min, x_max, y_max],...].
scores (np.ndarray): Confidence scores of detected objects of shape (N,).
labels (List[int], optional): Labels of detected objects of shape (N,). Defaults to None.
keypoints (List[List[Tuple[float, float]]], optional): Keypoints of detected objects of shape (N,2). Defaults to None.

Returns:
dai.ImgDetections OR ImgDetectionsWithKeypoints: Message containing the bounding boxes, labels, confidence scores, and keypoints of detected objects.
E{0}.

@param bbox: Detected bounding boxes of shape (N,4) meaning [...,[x_min, y_min, x_max, y_max],...].
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@type bbox: np.ndarray
@param scores: Confidence scores of detected objects of shape (N,).
@type scores: np.ndarray
@param labels: Labels of detected objects of shape (N,).
@type labels: List[int]
@param keypoints: Keypoints of detected objects of shape (N,2).
@type keypoints: List[List[Tuple[float, float]]]

@return: Message containing the bounding boxes, labels, confidence scores, and keypoints of detected objects.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@rtype: dai.ImgDetections OR ImgDetectionsWithKeypoints

@raise ValueError: If the bboxes are not a numpy array.
@raise ValueError: If the bboxes are not of shape (N,4).
@raise ValueError: If the bboxes 2nd dimension is not of size 4.
@raise ValueError: If the bboxes are not in format [x_min, y_min, x_max, y_max] where xmin < xmax and ymin < ymax.
@raise ValueError: If the scores are not a numpy array.
@raise ValueError: If the scores are not of shape (N,).
@raise ValueError: If the scores do not have the same length as bboxes.
@raise ValueError: If the labels are not a list.
@raise ValueError: If each label is not an integer.
@raise ValueError: If the labels do not have the same length as bboxes.
@raise ValueError: If the keypoints are not a list.
@raise ValueError: If each keypoint pair is not a tuple of two floats.
@raise ValueError: If the keypoints do not have the same length as bboxes.
"""

# checks for bboxes
Expand Down Expand Up @@ -125,12 +142,20 @@ def create_line_detection_message(lines: np.ndarray, scores: np.ndarray):
"""Create a message for the line detection. The message contains the lines and
confidence scores of detected lines.

Args:
lines (np.ndarray): Detected lines of shape (N,4) meaning [...,[x_start, y_start, x_end, y_end],...].
scores (np.ndarray): Confidence scores of detected lines of shape (N,).
@param lines: Detected lines of shape (N,4) meaning [...,[x_start, y_start, x_end, y_end],...].
@type lines: np.ndarray
@param scores: Confidence scores of detected lines of shape (N,).
@type scores: np.ndarray

@return: Message containing the lines and confidence scores of detected lines.
@rtype: Lines

Returns:
dai.Lines: Message containing the lines and confidence scores of detected lines.
@raise ValueError: If the lines are not a numpy array.
@raise ValueError: If the lines are not of shape (N,4).
@raise ValueError: If the lines 2nd dimension is not of size E{4}.
@raise ValueError: If the scores are not a numpy array.
@raise ValueError: If the scores are not of shape (N,).
@raise ValueError: If the scores do not have the same length as lines.
"""

# checks for lines
Expand Down
9 changes: 6 additions & 3 deletions depthai_nodes/ml/messages/creators/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ def create_image_message(
) -> dai.ImgFrame:
"""Create a depthai message for an image array.

@param image: Image array in HWC or CHW format.
@type image: np.array
@ivar image: Image array in HWC or CHW format.
@param is_bgr: If True, the image is in BGR format. If False, the image is in RGB
format. Defaults to True.
@type is_bgr: bool
@ivar is_bgr: If True, the image is in BGR format. If False, the image is in RGB
format.
@return: dai.ImgFrame object containing the image information.
@rtype: dai.ImgFrame
@raise ValueError: If the image shape is not CHW or HWC.
"""

if image.shape[0] in [1, 3]:
Expand Down
50 changes: 35 additions & 15 deletions depthai_nodes/ml/messages/creators/keypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@ def create_hand_keypoints_message(
"""Create a message for the hand keypoint detection. The message contains the 3D
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
coordinates of the detected hand keypoints, handedness, and confidence score.

Args:
hand_keypoints (np.ndarray): Detected hand keypoints of shape (N,3) meaning [...,[x, y, z],...].
handedness (float): Handedness score of the detected hand (left or right).
confidence (float): Confidence score of the detected hand.
confidence_threshold (float): Confidence threshold for the overall hand.

Returns:
HandKeypoints: Message containing the 3D coordinates of the detected hand keypoints, handedness, and confidence score.
@param hand_keypoints: Detected hand keypoints of shape (N,3) meaning [...,[x, y, z],...].
@type hand_keypoints: np.ndarray
@param handedness: Handedness score of the detected hand (left or right).
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@type handedness: float
@param confidence: Confidence score of the detected hand.
@type confidence: float
@param confidence_threshold: Confidence threshold for the overall hand.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@type confidence_threshold: float

@return: HandKeypoints message containing the 3D coordinates of the detected hand keypoints, handedness, and confidence score.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@rtype: HandKeypoints

@raise ValueError: If the hand_keypoints are not a numpy array.
@raise ValueError: If the hand_keypoints are not of shape (N,3).
@raise ValueError: If the hand_keypoints 2nd dimension is not of size E{3}.
@raise ValueError: If the handedness is not a float.
@raise ValueError: If the confidence is not a float.
"""

if not isinstance(hand_keypoints, np.ndarray):
Expand Down Expand Up @@ -66,13 +75,24 @@ def create_keypoints_message(
"""Create a message for the keypoints. The message contains 2D or 3D coordinates of
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
the detected keypoints.

Args:
keypoints (np.ndarray OR List[List[float]]): Detected keypoints of shape (N,2 or 3) meaning [...,[x, y],...] or [...,[x, y, z],...].
scores (np.ndarray or List[float]): Confidence scores of the detected keypoints.
confidence_threshold (float): Confidence threshold for the keypoints.

Returns:
Keypoints: Message containing 2D or 3D coordinates of the detected keypoints.
@param keypoints: Detected keypoints of shape (N,2 or 3) meaning [...,[x, y],...] or [...,[x, y, z],...].
@type keypoints: np.ndarray or List[List[float]]
@param scores: Confidence scores of the detected keypoints.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@type scores: np.ndarray or List[float]
@param confidence_threshold: Confidence threshold for the keypoints.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@type confidence_threshold: float

@return: Keypoints message containing 2D or 3D coordinates of the detected keypoints.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@rtype: Keypoints

@raise ValueError: If the keypoints are not a numpy array or list.
@raise ValueError: If the keypoints are not of shape (N,2 or 3).
@raise ValueError: If the keypoints 2nd dimension is not of size E{2} or E{3}.
@raise ValueError: If the scores are not a numpy array or list.
@raise ValueError: If the scores are not of shape (N,).
@raise ValueError: If the keypoints and scores do not have the same length.
@raise ValueError: If the confidence threshold is not a float.
@raise ValueError: If the confidence threshold is not provided when scores are provided.
"""

if not isinstance(keypoints, np.ndarray):
Expand Down
14 changes: 8 additions & 6 deletions depthai_nodes/ml/messages/creators/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

def create_segmentation_message(x: np.array) -> dai.ImgFrame:
"""Create a message for the segmentation node output. Input is of the shape (H, W,
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
1). In the third dimesion we specify the class of the segmented objects.
E{1}). In the third dimesion we specify the class of the segmented objects.

Args:
x (np.array): Input from the segmentation node.

Returns:
dai.ImgFrame: Output segmentaion message in ImgFrame.Type.RAW8.
@param x: Input from the segmentation node.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
@type x: np.array
@return: Output segmentaion message in ImgFrame.Type.RAW8.
@rtype: dai.ImgFrame
@raise ValueError: If the input is not a numpy array.
@raise ValueError: If the input is not 3D.
@raise ValueError: If the input 3rd dimension is not E{1}.
"""

if not isinstance(x, np.ndarray):
Expand Down
13 changes: 8 additions & 5 deletions depthai_nodes/ml/messages/creators/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ def create_thermal_message(thermal_image: np.array) -> dai.ImgFrame:
"""Creates a thermal image message in the form of an ImgFrame using the provided
kkeroo marked this conversation as resolved.
Show resolved Hide resolved
thermal image array.

Args:
thermal_image (np.array): A NumPy array representing the thermal image with shape (CHW or HWC).

Returns:
dai.ImgFrame: An ImgFrame object containing the thermal information.
@param thermal_image: A NumPy array representing the thermal image with shape (CHW
or HWC).
@type thermal_image: np.array
@return: An ImgFrame object containing the thermal information.
@rtype: dai.ImgFrame
@raise ValueError: If the input is not a NumPy array.
@raise ValueError: If the input is not 3D.
@raise ValueError: If the input shape is not CHW or HWC.
"""

if not isinstance(thermal_image, np.ndarray):
Expand Down
36 changes: 23 additions & 13 deletions depthai_nodes/ml/messages/creators/tracked_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
def create_feature_point(x: float, y: float, id: int, age: int) -> dai.TrackedFeature:
"""Create a tracked feature point.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved

Args:
x (float): X coordinate of the feature point.
y (float): Y coordinate of the feature point.
id (int): ID of the feature point.
age (int): Age of the feature point.

Returns:
dai.TrackedFeature: Tracked feature point.
@param x: X coordinate of the feature point.
@type x: float
@param y: Y coordinate of the feature point.
@type y: float
@param id: ID of the feature point.
@type id: int
@param age: Age of the feature point.
@type age: int
@return: Tracked feature point.
@rtype: dai.TrackedFeature
"""

feature = dai.TrackedFeature()
Expand All @@ -29,12 +31,20 @@ def create_tracked_features_message(
) -> dai.TrackedFeatures:
"""Create a message for the tracked features.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved

Args:
reference_points (np.ndarray): Reference points of shape (N,2) meaning [...,[x, y],...].
target_points (np.ndarray): Target points of shape (N,2) meaning [...,[x, y],...].
@param reference_points: Reference points of shape (N,2) meaning [...,[x, y],...].
@type reference_points: np.ndarray
@param target_points: Target points of shape (N,2) meaning [...,[x, y],...].
@type target_points: np.ndarray

@return: Message containing the tracked features.
@rtype: dai.TrackedFeatures

Returns:
dai.TrackedFeatures: Message containing the tracked features.
@raise ValueError: If the reference_points are not a numpy array.
@raise ValueError: If the reference_points are not of shape (N,2).
@raise ValueError: If the reference_points 2nd dimension is not of size E{2}.
@raise ValueError: If the target_points are not a numpy array.
@raise ValueError: If the target_points are not of shape (N,2).
@raise ValueError: If the target_points 2nd dimension is not of size E{2}.
"""

if not isinstance(reference_points, np.ndarray):
Expand Down
43 changes: 43 additions & 0 deletions depthai_nodes/ml/messages/img_detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,37 @@


class ImgDetectionWithKeypoints(dai.ImgDetection):
"""ImgDetectionWithKeypoints class for storing image detection with keypoints.

Attributes
----------
keypoints: List[Tuple[float, float]]
Keypoints of the image detection.
"""

def __init__(self):
"""Initializes the ImgDetectionWithKeypoints object."""
dai.ImgDetection.__init__(self) # TODO: change to super().__init__()?
self._keypoints: List[Tuple[float, float]] = []

@property
def keypoints(self) -> List[Tuple[float, float]]:
"""Returns the keypoints of the image detection.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved

@return: List of keypoints.
@rtype: List[Tuple[float, float]]
"""
return self._keypoints

@keypoints.setter
def keypoints(self, value: List[Tuple[Union[int, float], Union[int, float]]]):
"""Sets the keypoints of the image detection.
kkeroo marked this conversation as resolved.
Show resolved Hide resolved

@param value: List of keypoints.
@type value: List[Tuple[Union[int, float], Union[int, float]]]
@raise TypeError: If the keypoints are not a list.
@raise TypeError: If each keypoint is not a tuple of two floats or integers.
"""
if not isinstance(value, list):
raise TypeError("Keypoints must be a list")
for item in value:
Expand All @@ -29,16 +50,38 @@ def keypoints(self, value: List[Tuple[Union[int, float], Union[int, float]]]):


class ImgDetectionsWithKeypoints(dai.Buffer):
"""ImgDetectionsWithKeypoints class for storing image detections with keypoints.

Attributes
----------
detections: List[ImgDetectionWithKeypoints]
Image detections with keypoints.
"""

def __init__(self):
"""Initializes the ImgDetectionsWithKeypoints object."""
dai.Buffer.__init__(self) # TODO: change to super().__init__()?
self._detections: List[ImgDetectionWithKeypoints] = []

@property
def detections(self) -> List[ImgDetectionWithKeypoints]:
"""Returns the image detections with keypoints.

@return: List of image detections with keypoints.
@rtype: List[ImgDetectionWithKeypoints]
"""
return self._detections

@detections.setter
def detections(self, value: List[ImgDetectionWithKeypoints]):
"""Sets the image detections with keypoints.

@param value: List of image detections with keypoints.
@type value: List[ImgDetectionWithKeypoints]
@raise TypeError: If the detections are not a list.
@raise TypeError: If each detection is not an instance of
ImgDetectionWithKeypoints.
"""
if not isinstance(value, list):
raise TypeError("Detections must be a list")
for item in value:
Expand Down
Loading