From 9ad5e50ae9b1ecf1c0b1b809cde8ce114b2ae8e1 Mon Sep 17 00:00:00 2001 From: Rajarshi-Misra Date: Wed, 4 Oct 2023 17:59:03 +0530 Subject: [PATCH 1/8] Addition of gaussian blur filter --- supervision/annotators/core.py | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index d108af8e..c2d2bfa7 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -562,3 +562,66 @@ class LabelAnnotator: lineType=cv2.LINE_AA, ) return scene + + +class BlurAnnotator(BaseAnnotator): + """ + A class for blurring annotator. + """ + + def __init__(self, kernel_size: int = 5, sigmax: int = 0, sigmay: int = 0): + """ + Args: + color (Union[Color, ColorPalette]): The color or color palette to use for + annotating detections. + thickness (int): Thickness of the circle line. + color_map (str): Strategy for mapping colors to annotations. + Options are `index`, `class`, or `track`. + """ + self.kernel_size: int = kernel_size + self.sigmax = sigmax + self.sigmay = sigmay + + 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(...) + + >>> circle_annotator = sv.CircleAnnotator() + >>> annotated_frame = circle_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.GaussianBlur( + img=roi, size=self.kernel_size, sigmax=self.sigmax, sigmay=self.sigmay + ) + scene[y1:y2, x1:x2] = roi + + return scene From 9d5e53030ab953d953c935722c5c937cc5084b58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:25:36 +0000 Subject: [PATCH 2/8] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20?= =?UTF-8?q?format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/annotators/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index 72425d5f..7e3edf83 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -619,7 +619,7 @@ class BlurAnnotator(BaseAnnotator): scene[y1:y2, x1:x2] = roi return scene - + class TraceAnnotator: """ From 7366ba9036b7afde44fddc192b3153aa2a980aa5 Mon Sep 17 00:00:00 2001 From: Rajarshi-Misra <72802594+Rajarshi-Misra@users.noreply.github.com> Date: Wed, 4 Oct 2023 21:38:44 +0530 Subject: [PATCH 3/8] Error resolved --- supervision/__init__.py | 1 + supervision/annotators/core.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/supervision/__init__.py b/supervision/__init__.py index aab1eda8..1740dacb 100644 --- a/supervision/__init__.py +++ b/supervision/__init__.py @@ -9,6 +9,7 @@ except importlib_metadata.PackageNotFoundError: from supervision.annotators.core import ( BoundingBoxAnnotator, BoxCornerAnnotator, + BlurAnnotator, CircleAnnotator, EllipseAnnotator, LabelAnnotator, diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index 7e3edf83..55e8cefe 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -614,7 +614,7 @@ class BlurAnnotator(BaseAnnotator): roi = scene[y1:y2, x1:x2] roi = cv2.GaussianBlur( - img=roi, size=self.kernel_size, sigmax=self.sigmax, sigmay=self.sigmay + img=roi, size=(5,5), sigmax=self.sigmax, sigmay=self.sigmay ) scene[y1:y2, x1:x2] = roi From 331ccb8dde4125aef7c24e05c84e27d1b69680c8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:09:37 +0000 Subject: [PATCH 4/8] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20?= =?UTF-8?q?format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/__init__.py | 2 +- supervision/annotators/core.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/supervision/__init__.py b/supervision/__init__.py index 1740dacb..d6492af1 100644 --- a/supervision/__init__.py +++ b/supervision/__init__.py @@ -7,9 +7,9 @@ except importlib_metadata.PackageNotFoundError: __version__ = "development" from supervision.annotators.core import ( + BlurAnnotator, BoundingBoxAnnotator, BoxCornerAnnotator, - BlurAnnotator, CircleAnnotator, EllipseAnnotator, LabelAnnotator, diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index 55e8cefe..91808bc7 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -614,7 +614,7 @@ class BlurAnnotator(BaseAnnotator): roi = scene[y1:y2, x1:x2] roi = cv2.GaussianBlur( - img=roi, size=(5,5), sigmax=self.sigmax, sigmay=self.sigmay + img=roi, size=(5, 5), sigmax=self.sigmax, sigmay=self.sigmay ) scene[y1:y2, x1:x2] = roi From 7cf593b55db557e6c5ce016b5292ba62117017d9 Mon Sep 17 00:00:00 2001 From: Rajarshi-Misra <72802594+Rajarshi-Misra@users.noreply.github.com> Date: Wed, 4 Oct 2023 21:47:24 +0530 Subject: [PATCH 5/8] Replaced with blur filter --- supervision/annotators/core.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index 91808bc7..f058d111 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -570,7 +570,7 @@ class BlurAnnotator(BaseAnnotator): A class for blurring annotator. """ - def __init__(self, kernel_size: int = 5, sigmax: int = 0, sigmay: int = 0): + def __init__(self, kernel_size: int = 15): """ Args: color (Union[Color, ColorPalette]): The color or color palette to use for @@ -580,8 +580,7 @@ class BlurAnnotator(BaseAnnotator): Options are `index`, `class`, or `track`. """ self.kernel_size: int = kernel_size - self.sigmax = sigmax - self.sigmay = sigmay + def annotate( self, @@ -613,8 +612,8 @@ class BlurAnnotator(BaseAnnotator): x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int) roi = scene[y1:y2, x1:x2] - roi = cv2.GaussianBlur( - img=roi, size=(5, 5), sigmax=self.sigmax, sigmay=self.sigmay + roi = cv2.blur( + roi, (kernel_size, kernel_size) ) scene[y1:y2, x1:x2] = roi From a0b64342caaa1a51a967eba210e8d73fd6ac8cd4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:17:35 +0000 Subject: [PATCH 6/8] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20?= =?UTF-8?q?format=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/annotators/core.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index f058d111..b1b28606 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -580,7 +580,6 @@ class BlurAnnotator(BaseAnnotator): Options are `index`, `class`, or `track`. """ self.kernel_size: int = kernel_size - def annotate( self, @@ -612,9 +611,7 @@ class BlurAnnotator(BaseAnnotator): x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int) roi = scene[y1:y2, x1:x2] - roi = cv2.blur( - roi, (kernel_size, kernel_size) - ) + roi = cv2.blur(roi, (kernel_size, kernel_size)) scene[y1:y2, x1:x2] = roi return scene From 4fd1ba4dd36ce555328f7be92f3a99ce14e648ee Mon Sep 17 00:00:00 2001 From: Hardik Dava <39372750+hardikdava@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:34:51 +0200 Subject: [PATCH 7/8] Update var type --- supervision/annotators/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index b1b28606..f0c0b2a5 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -611,7 +611,7 @@ class BlurAnnotator(BaseAnnotator): x1, y1, x2, y2 = detections.xyxy[detection_idx].astype(int) roi = scene[y1:y2, x1:x2] - roi = cv2.blur(roi, (kernel_size, kernel_size)) + roi = cv2.blur(roi, (self.kernel_size, self.kernel_size)) scene[y1:y2, x1:x2] = roi return scene From 1d0ffeba72a8f32c7da8afae618c22b950a591d0 Mon Sep 17 00:00:00 2001 From: Rajarshi-Misra <72802594+Rajarshi-Misra@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:23:54 +0530 Subject: [PATCH 8/8] Comments corrected --- supervision/annotators/core.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/supervision/annotators/core.py b/supervision/annotators/core.py index f0c0b2a5..930420d4 100644 --- a/supervision/annotators/core.py +++ b/supervision/annotators/core.py @@ -573,11 +573,7 @@ class BlurAnnotator(BaseAnnotator): def __init__(self, kernel_size: int = 15): """ Args: - color (Union[Color, ColorPalette]): The color or color palette to use for - annotating detections. - thickness (int): Thickness of the circle line. - color_map (str): Strategy for mapping colors to annotations. - Options are `index`, `class`, or `track`. + kernel_size: the size of the average pooling kernel used for blurring """ self.kernel_size: int = kernel_size @@ -598,8 +594,8 @@ class BlurAnnotator(BaseAnnotator): >>> import supervision as sv >>> image = ... >>> detections = sv.Detections(...) - >>> circle_annotator = sv.CircleAnnotator() - >>> annotated_frame = circle_annotator.annotate( + >>> blue_annotator = sv.BlurAnnotator() + >>> annotated_frame = blur_annotator.annotate( ... scene=image.copy(), ... detections=detections ... )