From 6128576ea1c0fea0d05ef855fa673bb7c7207274 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 18 Jan 2024 16:06:10 +0000 Subject: [PATCH] =?UTF-8?q?fix(pre=5Fcommit):=20=F0=9F=8E=A8=20auto=20form?= =?UTF-8?q?at=20pre-commit=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/speed_estimation/README.md | 4 +-- supervision/detection/line_counter.py | 44 +++++++++++++-------------- supervision/geometry/core.py | 2 +- test/detection/test_line_counter.py | 24 +++++++-------- test/geometry/test_core.py | 6 ++-- 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/examples/speed_estimation/README.md b/examples/speed_estimation/README.md index 956020e4..46a97e5c 100644 --- a/examples/speed_estimation/README.md +++ b/examples/speed_estimation/README.md @@ -11,10 +11,10 @@ supervision package for multiple tasks such as tracking, annotations, etc. https://github.com/roboflow/supervision/assets/26109316/d50118c1-2ae4-458d-915a-5d860fd36f71 -> [!IMPORTANT] +> [!IMPORTANT] > Adjust the [`SOURCE`](https://github.com/roboflow/supervision/blob/e32b05a636dab2ea1f39299e529c4b22b8baa8da/examples/speed_estimation/ultralytics_example.py#L10) > and [`TARGET`](https://github.com/roboflow/supervision/blob/e32b05a636dab2ea1f39299e529c4b22b8baa8da/examples/speed_estimation/ultralytics_example.py#L15) -> configuration if you plan to run a speed estimation script on your video file. Those must be adjusted separately for each camera view. You can learn more +> configuration if you plan to run a speed estimation script on your video file. Those must be adjusted separately for each camera view. You can learn more > from our YouTube [tutorial](https://youtu.be/uWP6UjDeZvY). ## 💻 install diff --git a/supervision/detection/line_counter.py b/supervision/detection/line_counter.py index 179a07a5..0b8a1321 100644 --- a/supervision/detection/line_counter.py +++ b/supervision/detection/line_counter.py @@ -1,11 +1,11 @@ -from typing import Dict, Optional, Tuple, List, Iterable +from typing import Dict, Iterable, Optional, Tuple import cv2 import numpy as np from supervision.detection.core import Detections from supervision.draw.color import Color -from supervision.geometry.core import Point, Rect, Vector, Position +from supervision.geometry.core import Point, Position, Rect, Vector class LineZone: @@ -34,8 +34,8 @@ class LineZone: Position.TOP_LEFT, Position.TOP_RIGHT, Position.BOTTOM_LEFT, - Position.BOTTOM_RIGHT - ) + Position.BOTTOM_RIGHT, + ), ): """ Args: @@ -74,15 +74,15 @@ class LineZone: start=vector.start, end=Point( x=vector.start.x + perpendicular_vector_x, - y=vector.start.y + perpendicular_vector_y - ) + y=vector.start.y + perpendicular_vector_y, + ), ) end_region_limit = Vector( start=vector.end, end=Point( x=vector.end.x - perpendicular_vector_x, - y=vector.end.y - perpendicular_vector_y - ) + y=vector.end.y - perpendicular_vector_y, + ), ) return start_region_limit, end_region_limit @@ -112,11 +112,12 @@ class LineZone: if len(detections) == 0: return crossed_in, crossed_out - all_anchors = np.array([ - detections.get_anchors_coordinates(anchor) - for anchor - in self.triggering_anchors - ]) + all_anchors = np.array( + [ + detections.get_anchors_coordinates(anchor) + for anchor in self.triggering_anchors + ] + ) for i, tracker_id in enumerate(detections.tracker_id): if tracker_id is None: @@ -124,19 +125,18 @@ class LineZone: box_anchors = [Point(x=x, y=y) for x, y in all_anchors[:, i, :]] - in_limits = all([ - self.is_point_in_limits(point=anchor, limits=self.limits) - for anchor - in box_anchors - ]) + in_limits = all( + [ + self.is_point_in_limits(point=anchor, limits=self.limits) + for anchor in box_anchors + ] + ) if not in_limits: continue triggers = [ - self.vector.cross_product(point=anchor) > 0 - for anchor - in box_anchors + self.vector.cross_product(point=anchor) > 0 for anchor in box_anchors ] if len(set(triggers)) == 2: @@ -323,4 +323,4 @@ class LineZoneAnnotator: self.text_thickness, cv2.LINE_AA, ) - return frame \ No newline at end of file + return frame diff --git a/supervision/geometry/core.py b/supervision/geometry/core.py index 468f43db..3e4ee462 100644 --- a/supervision/geometry/core.py +++ b/supervision/geometry/core.py @@ -54,7 +54,7 @@ class Vector: """ dx = self.end.x - self.start.x dy = self.end.y - self.start.y - return sqrt(dx ** 2 + dy ** 2) + return sqrt(dx**2 + dy**2) def cross_product(self, point: Point) -> float: """ diff --git a/test/detection/test_line_counter.py b/test/detection/test_line_counter.py index c1231b0d..73780414 100644 --- a/test/detection/test_line_counter.py +++ b/test/detection/test_line_counter.py @@ -1,10 +1,10 @@ from contextlib import ExitStack as DoesNotRaise -from typing import Tuple, Optional +from typing import Optional, Tuple import pytest from supervision import LineZone -from supervision.geometry.core import Vector, Point +from supervision.geometry.core import Point, Vector @pytest.mark.parametrize( @@ -13,18 +13,18 @@ from supervision.geometry.core import Vector, Point ( Vector(start=Point(x=0.0, y=0.0), end=Point(x=0.0, y=0.0)), None, - pytest.raises(ValueError) + pytest.raises(ValueError), ), ( Vector(start=Point(x=1.0, y=1.0), end=Point(x=1.0, y=1.0)), None, - pytest.raises(ValueError) + pytest.raises(ValueError), ), ( Vector(start=Point(x=0.0, y=0.0), end=Point(x=0.0, y=4.0)), ( Vector(start=Point(x=0.0, y=0.0), end=Point(x=-1.0, y=0.0)), - Vector(start=Point(x=0.0, y=4.0), end=Point(x=1.0, y=4.0)) + Vector(start=Point(x=0.0, y=4.0), end=Point(x=1.0, y=4.0)), ), DoesNotRaise(), ), @@ -32,7 +32,7 @@ from supervision.geometry.core import Vector, Point Vector(Point(0.0, 0.0), Point(4.0, 0.0)), ( Vector(start=Point(x=0.0, y=0.0), end=Point(x=0.0, y=1.0)), - Vector(start=Point(x=4.0, y=0.0), end=Point(x=4.0, y=-1.0)) + Vector(start=Point(x=4.0, y=0.0), end=Point(x=4.0, y=-1.0)), ), DoesNotRaise(), ), @@ -40,7 +40,7 @@ from supervision.geometry.core import Vector, Point Vector(Point(0.0, 0.0), Point(3.0, 4.0)), ( Vector(start=Point(x=0, y=0), end=Point(x=-0.8, y=0.6)), - Vector(start=Point(x=3, y=4), end=Point(x=3.8, y=3.4)) + Vector(start=Point(x=3, y=4), end=Point(x=3.8, y=3.4)), ), DoesNotRaise(), ), @@ -48,7 +48,7 @@ from supervision.geometry.core import Vector, Point Vector(Point(0.0, 0.0), Point(4.0, 3.0)), ( Vector(start=Point(x=0, y=0), end=Point(x=-0.6, y=0.8)), - Vector(start=Point(x=4, y=3), end=Point(x=4.6, y=2.2)) + Vector(start=Point(x=4, y=3), end=Point(x=4.6, y=2.2)), ), DoesNotRaise(), ), @@ -56,16 +56,16 @@ from supervision.geometry.core import Vector, Point Vector(Point(0.0, 0.0), Point(3.0, -4.0)), ( Vector(start=Point(x=0, y=0), end=Point(x=0.8, y=0.6)), - Vector(start=Point(x=3, y=-4), end=Point(x=2.2, y=-4.6)) + Vector(start=Point(x=3, y=-4), end=Point(x=2.2, y=-4.6)), ), DoesNotRaise(), - ) - ] + ), + ], ) def test_calculate_region_of_interest_limits( vector: Vector, expected_result: Optional[Tuple[Vector, Vector]], - exception: Exception + exception: Exception, ) -> None: with exception: result = LineZone.calculate_region_of_interest_limits(vector=vector) diff --git a/test/geometry/test_core.py b/test/geometry/test_core.py index da22eed1..f113fec9 100644 --- a/test/geometry/test_core.py +++ b/test/geometry/test_core.py @@ -27,9 +27,7 @@ from supervision.geometry.core import Point, Vector ], ) def test_vector_cross_product( - vector: Vector, - point: Point, - expected_result: float + vector: Vector, point: Point, expected_result: float ) -> None: result = vector.cross_product(point=point) assert result == expected_result @@ -54,7 +52,7 @@ def test_vector_cross_product( (Vector(start=Point(x=0, y=0), end=Point(x=4, y=3)), 5.0), (Vector(start=Point(x=3, y=4), end=Point(x=0, y=0)), 5.0), (Vector(start=Point(x=4, y=3), end=Point(x=0, y=0)), 5.0), - ] + ], ) def test_vector_magnitude(vector: Vector, expected_result: float) -> None: result = vector.magnitude