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

cornered box annotator #171

Merged
merged 19 commits into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ def get_version():
'numpy>=1.20.0',
'opencv-python',
'matplotlib',
'pyyaml'
'pyyaml',
'pillow'
],
packages=find_packages(exclude=("tests",)),
extras_require={
Expand Down
11 changes: 11 additions & 0 deletions supervision/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
__version__ = "0.11.1"

from supervision.annotators.composable import DetectionAnnotator, SegmentationAnnotator
from supervision.annotators.core import (
BoxCornerAnnotator,
BoxLineAnnotator,
BoxMaskAnnotator,
EllipseAnnotator,
LabelAdvancedAnnotator,
LabelAnnotator,
MaskAnnotator,
build_label_formatter,
)
from supervision.classification.core import Classifications
from supervision.dataset.core import (
BaseDataset,
Expand Down
92 changes: 84 additions & 8 deletions supervision/annotators/composable.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,94 @@
from abc import ABC
from typing import List
from typing import List, Optional

import numpy as np

from supervision.annotators.core import BaseAnnotator
from supervision.annotators.core import BoxAnnotator, LabelAnnotator, MaskAnnotator
from supervision.detection.core import Detections


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

def annotate(self, scene: np.ndarray, detections: Detections) -> np.ndarray:
annotated_image = scene
def annotate(
self,
scene: np.ndarray,
detections: Detections,
labels: Optional[List[str]] = None,
) -> np.ndarray:
for annotator in self.annotators:
annotated_image = annotator.annotate(scene=scene, detections=detections)
return annotated_image
if isinstance(annotator, LabelAnnotator):
scene = annotator.annotate(
scene=scene,
detections=detections,
labels=labels,
)
else:
scene = annotator.annotate(scene=scene, detections=detections)
return scene


class DetectionAnnotator(ComposableAnnotator):
"""
Highlevel API for drawing Object Detection output. This will use Box and Label Annotators
Example:
```python
>>> import supervision as sv

>>> classes = ['person', ...]
>>> image = ...
>>> detections = sv.Detections(...)

>>> detection_annotator = sv.DetectionAnnotator()
>>> annotated_frame = detection_annotator.annotate(
... scene=image.copy(),
... detections=detections
... )
```
"""

def __init__(
self,
color_by_track: bool = False,
skip_label: bool = False,
):
super().__init__()
self.annotators = [BoxAnnotator(color_by_track=color_by_track)]
if not skip_label:
self.annotators.append(LabelAnnotator(color_by_track=color_by_track))


class SegmentationAnnotator(ComposableAnnotator):
"""
High level API for drawing segmentation mask, bounding box and labels on an image using provided detections.
Example:
```python
>>> import supervision as sv

>>> classes = ['person', ...]
>>> image = ...
>>> detections = sv.Detections(...)

>>> segmentation_annotator = sv.SegmentationAnnotator()
>>> annotated_frame = segmentation_annotator.annotate(
... scene=image.copy(),
... detections=detections
... )
```
"""

def __init__(
self,
color_by_track: bool = False,
skip_label: bool = False,
):
super().__init__()
self.annotators = [
BoxAnnotator(color_by_track=color_by_track),
MaskAnnotator(color_by_track=color_by_track),
]
if not skip_label:
self.annotators.append(LabelAnnotator(color_by_track=color_by_track))
Loading