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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced BoxAnnotator馃ぉ #168

Closed
2 of 5 tasks
hardikdava opened this issue Jun 29, 2023 · 21 comments
Closed
2 of 5 tasks

Advanced BoxAnnotator馃ぉ #168

hardikdava opened this issue Jun 29, 2023 · 21 comments
Assignees
Labels
enhancement New feature or request version: 0.12.0 Feature to be added in `0.12.0` release version: 0.13.0 Feature to be added in `0.13.0` release version 0.14.0 Feature to be added in `0.14.0` release version: 0.15.0 Feature to be added in `0.15.0` release

Comments

@hardikdava
Copy link
Collaborator

Search before asking

  • I have searched the Supervision issues and found no similar feature requests.

Description

Current sv.BoxAnnotator is drawing boxes based on opencv rectangle. It can be improved for this kind of boxes. This looks pretty cool!

  • Advanced corner based bounding boxes
  • Blur capacity (Direct object blur application)
  • Boxes as mask
Screenshot 2023-06-29 234656 image source: depthai blogs

Use case

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@hardikdava hardikdava added the enhancement New feature or request label Jun 29, 2023
@SkalskiP SkalskiP self-assigned this Jun 29, 2023
@SkalskiP
Copy link
Collaborator

@hardikdava Haha I see you want to do annotators :) How about we do this first? #49

@hardikdava
Copy link
Collaborator Author

Preliminary result:
result

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 1, 2023

Uuuu! Looks cool! 馃敟

I drove for a few hours yesterday and thought a lot about our annotators. And I think we can use that opportunity to redesign that feature and make it even more flexible. I think we should split annotators and make them composable. What do you think @hardikdava?

Here is my idea:

import numpy as np

from abc import ABC, abstractmethod

from typing import List


# base annotator

class BaseAnnotator(ABC):

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        pass


class ComposableAnnotator(ABC):

    def __init__(self, annotators: List[BaseAnnotator]):
        self.annotators = annotators

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        annotated_image = scene
        for annotator in self.annotators:
            annotated_image = annotator.annotate(scene=scene, detections=detections)
        return annotated_image

# single responsibility annotator

class BoxAnnotator(BaseAnnotator):

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        pass


class PolygonMaskAnnotator(BaseAnnotator):

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        pass


class LabelAnnotator(BaseAnnotator):

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        pass


class PillowLabelAnnotator(BaseAnnotator):

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        pass


class TrackAnnotator(BaseAnnotator):

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        pass


class BoxMaskAnnotator(BaseAnnotator):

    def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
        pass

# high level annotators

class DetectionAnnotator(ComposableAnnotator):

    @classmethod
    def init(cls):
        annotators = [
            BoxAnnotator(),
            LabelAnnotator()
        ]
        return cls(annotators=annotators)


class SegmentationAnnotator(ComposableAnnotator):

    @classmethod
    def init(cls):
        annotators = [
            BoxAnnotator(),
            LabelAnnotator()
        ]
        return cls(annotators=annotators)


class TrackedDetectionAnnotator(ComposableAnnotator):

    @classmethod
    def init(cls):
        annotators = [
            BoxAnnotator(),
            LabelAnnotator(),
            TrackAnnotator()
        ]
        return cls(annotators=annotators)

@hardikdava
Copy link
Collaborator Author

Hey @SkalskiP 馃憢 , this is actually a nice idea of having computer vision task based annotators along with single responsible annotators. pillow annotators are actually a good idea but I found that pillow is much slower than opencv in terms of drawing operations from my experience. But having it is a good option. Since there are a lot possibilites of drawing for example it allows to use custom fonts which opencv doesn't allow. It will be a feature for future release. I would suggest to create an issue for this for now. We should first try to solve the existing issues.

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 1, 2023

Hi @hardikdava 馃憢馃徎 ! I know pillow is slower than opencv, but opencv only allows you to use ascii characters in the text. We already had a lot of voices from the community that they would like to add text in Arabic or Chinese.

But I mostly mean to give people base annotators that they could freely combine.

@hardikdava
Copy link
Collaborator Author

Hi @SkalskiP 馃憢 , I am 馃挴 agree with you about adding pillow. It is good to have.

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 1, 2023

@hardikdava how about the overall idea? 馃挕

@hardikdava
Copy link
Collaborator Author

hardikdava commented Jul 1, 2023

I would keep this as simple as possible. User can choose between cv and pillow with one flag. Creating different Annotators will create lot of confusion in usage and practice.

class BoxAnnotator(BaseAnnotator):

    def annotate(self, scene: np.ndarray, detections: Detectionsm, use_pillow: bool=False) -> np.ndarray:
        if use_pillow:
            scene = self._annotate_pillow()
            return scene
        else:
            scene = self._annotate_cv()
            return scene
    def _annotate_cv(self):
        pass
     def _annotate_pillow(self):
        pass

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 1, 2023

I don鈥檛 want to use pillow for drawing boxes. I want to use pillow only for text annotation and I want to separate drawing labels from drawing boxes.

@hardikdava
Copy link
Collaborator Author

@SkalskiP Overall, this is really good idea and your suggested APIs are good for future. It is highly scalabel.

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 1, 2023

Exactly. Problem is that we would need to do it in the way that people could migrate from old API to new API.

@hardikdava
Copy link
Collaborator Author

I do not think of any problems of migration with the suggested API. This will work without any issue.

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 2, 2023

@hardikdava I'll create the initial PR to set up the structure, and we will migrate all annotators one by one. Okey?

@hardikdava
Copy link
Collaborator Author

@SkalskiP okay. I will be waiting for the issue.

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 2, 2023

@hardikdava can you open PR with this annotator into the feature/redesigned_annotators branch?

@hardikdava
Copy link
Collaborator Author

@hardikdava can you open PR with this annotator into the feature/redesigned_annotators branch?

Of course. I will make a PR.

@hardikdava hardikdava mentioned this issue Jul 3, 2023
1 task
@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 4, 2023

Hi @hardikdava 馃憢馃徎! Sorry I move so slowly. I'm doing a lot of stuff other than supervision this week. :/

@hardikdava
Copy link
Collaborator Author

@SkalskiP understood. It's fine. I am working on Annotators and trying to answer in the issues. Take your time and later try to test and merge the functions.

@SkalskiP SkalskiP added the version: 0.12.0 Feature to be added in `0.12.0` release label Jul 4, 2023
@maddust
Copy link

maddust commented Jul 11, 2023

Just an idea I added to my project to have a visual bbox queue of when an object triggers a PolygonZone or LineZone , also check the crop slideshow on the bottom

bbox2

@SkalskiP SkalskiP added this to the version: 0.12.0 milestone Jul 18, 2023
@SkalskiP
Copy link
Collaborator

@maddust 馃敟! This looks amazing! You are truly a supervision power user!

@SkalskiP SkalskiP added the version: 0.13.0 Feature to be added in `0.13.0` release label Jul 23, 2023
@SkalskiP SkalskiP added the version 0.14.0 Feature to be added in `0.14.0` release label Aug 11, 2023
@SkalskiP SkalskiP added the version: 0.15.0 Feature to be added in `0.15.0` release label Oct 5, 2023
@SkalskiP
Copy link
Collaborator

SkalskiP commented Oct 5, 2023

This task is finally completed with: https://github.com/roboflow/supervision/releases/tag/0.15.0 馃敟

@SkalskiP SkalskiP closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request version: 0.12.0 Feature to be added in `0.12.0` release version: 0.13.0 Feature to be added in `0.13.0` release version 0.14.0 Feature to be added in `0.14.0` release version: 0.15.0 Feature to be added in `0.15.0` release
Projects
Status: Current Release: Done
Development

No branches or pull requests

3 participants