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

Feat/annotation builder #178

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Feat/annotation builder #178

wants to merge 7 commits into from

Conversation

tadeas0
Copy link

@tadeas0 tadeas0 commented Feb 27, 2025

Purpose

Create AnnotationHelper class to simplify dai.ImgAnnotations message creation.

Dependencies & Potential Impact

None / not applicable

Deployment Plan

None / not applicable

Testing & Validation

None / not applicable

@tadeas0 tadeas0 requested a review from dominik737 February 27, 2025 11:36
@github-actions github-actions bot added the enhancement New feature or request label Feb 27, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2025

❌ 5 Tests Failed:

Tests completed Failed Passed Skipped
233 5 228 2
View the top 3 failed test(s) by shortest run time
tests/unittests/test_helpers/test_annotation_helper.py::test_draw_points
Stack Traces | 0.001s run time
def test_draw_points():
        annotation_helper = AnnotationHelper()
>       annotation_helper.draw_points([(0.0, 0.0), (1.0, 1.0)], (1.0, 0.0, 0.0, 1.0), 2)

tests\unittests\test_helpers\test_annotation_helper.py:158: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
depthai_nodes\utils\annotation_helper.py:96: in draw_points
    points_annot = self._create_points_annotation(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <depthai_nodes.utils.annotation_helper.AnnotationHelper object at 0x000001DFB7C87040>
points = [(0.0, 0.0), (1.0, 1.0)], color = (1.0, 0.0, 0.0, 1.0)
fill_color = None, type = <PointsAnnotationType.POINTS: 1>

    def _create_points_annotation(
        self,
        points: List[Point],
        color: ColorRGBA,
        fill_color: Optional[ColorRGBA],
        type: dai.PointsAnnotationType,
    ) -> dai.PointsAnnotation:
        points_annot = dai.PointsAnnotation()
        points_annot.outlineColor = self._create_color(color)
        if fill_color is not None:
            points_annot.fillColor = self._create_color(fill_color)
        points_annot.type = type
>       points_annot.points = self._create_points_vector(points)
E       TypeError: (): incompatible function arguments. The following argument types are supported:
E           1. (self: depthai.PointsAnnotation, arg0: depthai.VectorPoint2f) -> None
E       
E       Invoked with: <depthai.PointsAnnotation object at 0x000001DFB7D044F0>, <depthai.VectorPoint2f object at 0x000001DFB7D049B0>

depthai_nodes\utils\annotation_helper.py:260: TypeError
tests/unittests/test_helpers/test_annotation_helper.py::test_draw_polyline
Stack Traces | 0.001s run time
def test_draw_polyline():
        annotation_helper = AnnotationHelper()
>       annotation_helper.draw_polyline(
            [(0.0, 0.0), (0.5, 0.5), (1.0, 1.0)],
            (1.0, 0.0, 0.0, 1.0),
            (0.0, 1.0, 0.0, 1.0),
            2,
            True,
        )

tests\unittests\test_helpers\test_annotation_helper.py:35: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
depthai_nodes\utils\annotation_helper.py:74: in draw_polyline
    points_annot = self._create_points_annotation(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <depthai_nodes.utils.annotation_helper.AnnotationHelper object at 0x000001DFB7D62920>
points = [(0.0, 0.0), (0.5, 0.5), (1.0, 1.0)], color = (1.0, 0.0, 0.0, 1.0)
fill_color = (0.0, 1.0, 0.0, 1.0), type = <PointsAnnotationType.LINE_LOOP: 2>

    def _create_points_annotation(
        self,
        points: List[Point],
        color: ColorRGBA,
        fill_color: Optional[ColorRGBA],
        type: dai.PointsAnnotationType,
    ) -> dai.PointsAnnotation:
        points_annot = dai.PointsAnnotation()
        points_annot.outlineColor = self._create_color(color)
        if fill_color is not None:
            points_annot.fillColor = self._create_color(fill_color)
        points_annot.type = type
>       points_annot.points = self._create_points_vector(points)
E       TypeError: (): incompatible function arguments. The following argument types are supported:
E           1. (self: depthai.PointsAnnotation, arg0: depthai.VectorPoint2f) -> None
E       
E       Invoked with: <depthai.PointsAnnotation object at 0x000001DFB6A43DB0>, <depthai.VectorPoint2f object at 0x000001DFB6A40970>

depthai_nodes\utils\annotation_helper.py:260: TypeError
tests/unittests/test_helpers/test_annotation_helper.py::test_draw_polyline_closed
Stack Traces | 0.001s run time
def test_draw_polyline_closed():
        annotation_helper = AnnotationHelper()
>       annotation_helper.draw_polyline(
            [(0.0, 0.0), (0.5, 0.5), (1.0, 1.0)],
            (1.0, 0.0, 0.0, 1.0),
            None,
            2,
            False,
        )

tests\unittests\test_helpers\test_annotation_helper.py:63: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
depthai_nodes\utils\annotation_helper.py:74: in draw_polyline
    points_annot = self._create_points_annotation(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <depthai_nodes.utils.annotation_helper.AnnotationHelper object at 0x000001DFB7F554B0>
points = [(0.0, 0.0), (0.5, 0.5), (1.0, 1.0)], color = (1.0, 0.0, 0.0, 1.0)
fill_color = None, type = <PointsAnnotationType.LINE_STRIP: 3>

    def _create_points_annotation(
        self,
        points: List[Point],
        color: ColorRGBA,
        fill_color: Optional[ColorRGBA],
        type: dai.PointsAnnotationType,
    ) -> dai.PointsAnnotation:
        points_annot = dai.PointsAnnotation()
        points_annot.outlineColor = self._create_color(color)
        if fill_color is not None:
            points_annot.fillColor = self._create_color(fill_color)
        points_annot.type = type
>       points_annot.points = self._create_points_vector(points)
E       TypeError: (): incompatible function arguments. The following argument types are supported:
E           1. (self: depthai.PointsAnnotation, arg0: depthai.VectorPoint2f) -> None
E       
E       Invoked with: <depthai.PointsAnnotation object at 0x000001DFB7CCD2F0>, <depthai.VectorPoint2f object at 0x000001DFB7CCDAF0>

depthai_nodes\utils\annotation_helper.py:260: TypeError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link
Contributor

@dominik737 dominik737 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

ColorRGBA = Tuple[float, float, float, float]


class AnnotationHelper:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of this class used to be AnnotationBuilder, why was it replaced for AnnotationHelper? I think that AnnotationBuilder is more suiting name.

Copy link
Collaborator

@jkbmrz jkbmrz Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why not an ImgAnnotationBuilder if it refers to dai.ImgAnnotation creation?

Copy link
Author

@tadeas0 tadeas0 Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name was changed after some discussion in this slack thread. Personally I don't have any strong opinions on the name of this class, so we can go with whatever you prefer.

@dominik737
Copy link
Contributor

dominik737 commented Feb 27, 2025

Also I would consider moving the class from depthai-nodes.ml.helpers.utils to depthai-nodes.utils as the class does not directly relate to ml. And have the class in the __init__ file.

Copy link
Collaborator

@kkeroo kkeroo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ColorRGBA = Tuple[float, float, float, float]


class AnnotationHelper:
Copy link
Collaborator

@jkbmrz jkbmrz Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why not an ImgAnnotationBuilder if it refers to dai.ImgAnnotation creation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants