Merge pull request #405 from Rajarshi-Misra/new1

Create sv.BlurAnnotator #395
This commit is contained in:
Piotr Skalski
2023-10-04 23:29:26 +02:00
committed by GitHub
2 changed files with 49 additions and 0 deletions
+1
View File
@@ -7,6 +7,7 @@ except importlib_metadata.PackageNotFoundError:
__version__ = "development"
from supervision.annotators.core import (
BlurAnnotator,
BoundingBoxAnnotator,
BoxCornerAnnotator,
CircleAnnotator,
+48
View File
@@ -565,6 +565,54 @@ class LabelAnnotator:
return scene
class BlurAnnotator(BaseAnnotator):
"""
A class for blurring annotator.
"""
def __init__(self, kernel_size: int = 15):
"""
Args:
kernel_size: the size of the average pooling kernel used for blurring
"""
self.kernel_size: int = kernel_size
def annotate(
self,
scene: np.ndarray,
detections: Detections,
) -> np.ndarray:
"""
Annotates the given scene with circles based on the provided detections.
Args:
scene (np.ndarray): The image where box corners will be drawn.
detections (Detections): Object detections to annotate.
Returns:
np.ndarray: The annotated image.
Example:
```python
>>> import supervision as sv
>>> image = ...
>>> detections = sv.Detections(...)
>>> blue_annotator = sv.BlurAnnotator()
>>> annotated_frame = blur_annotator.annotate(
... scene=image.copy(),
... detections=detections
... )
```
![circle-annotator-example](https://media.roboflow.com/
supervision-annotator-examples/circle-annotator-example.png)
"""
for detection_idx in range(len(detections)):
x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int)
roi = scene[y1:y2, x1:x2]
roi = cv2.blur(roi, (self.kernel_size, self.kernel_size))
scene[y1:y2, x1:x2] = roi
return scene
class TraceAnnotator:
"""
A class for drawing trace paths on an image based on detection coordinates.