fix(pre_commit): 🎨 auto format pre-commit hooks

This commit is contained in:
pre-commit-ci[bot] 2024-01-18 16:06:10 +00:00
parent cda5016a5a
commit 6128576ea1
5 changed files with 39 additions and 41 deletions

View File

@ -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

View File

@ -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
return frame

View File

@ -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:
"""

View File

@ -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)

View File

@ -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