First batch of basic tools:

- 🎨 DEFAULT_COLOR_PALETTE, Color and ColorPalette classes
- 📐 initial implementation of Point, Vector and Rect classes
- 🎬 VideoInfo and VideoSink classes as well as get_video_frames_generator
- 📓 show_frame_in_notebook util
This commit is contained in:
SkalskiP
2023-01-18 19:27:51 +01:00
parent a4e60f33ba
commit 3dad4f4a4d
21 changed files with 436 additions and 161 deletions
View File
View File
+40
View File
@@ -0,0 +1,40 @@
import pytest
from supervision.commons.dataclasses import Vector, Point
@pytest.mark.parametrize(
'vector, point, expected_result',
[
(Vector(start=Point(x=0, y=0), end=Point(x=5, y=5)), Point(x=-1, y=1), False),
(Vector(start=Point(x=0, y=0), end=Point(x=5, y=5)), Point(x=6, y=6), False),
(Vector(start=Point(x=0, y=0), end=Point(x=5, y=5)), Point(x=3, y=6), False),
(Vector(start=Point(x=5, y=5), end=Point(x=0, y=0)), Point(x=-1, y=1), True),
(Vector(start=Point(x=5, y=5), end=Point(x=0, y=0)), Point(x=6, y=6), False),
(Vector(start=Point(x=5, y=5), end=Point(x=0, y=0)), Point(x=3, y=6), True),
(Vector(start=Point(x=0, y=0), end=Point(x=1, y=0)), Point(x=0, y=0), False),
(Vector(start=Point(x=0, y=0), end=Point(x=1, y=0)), Point(x=0, y=-1), True),
(Vector(start=Point(x=0, y=0), end=Point(x=1, y=0)), Point(x=0, y=1), False),
(Vector(start=Point(x=1, y=0), end=Point(x=0, y=0)), Point(x=0, y=0), False),
(Vector(start=Point(x=1, y=0), end=Point(x=0, y=0)), Point(x=0, y=-1), False),
(Vector(start=Point(x=1, y=0), end=Point(x=0, y=0)), Point(x=0, y=1), True),
(Vector(start=Point(x=1, y=1), end=Point(x=1, y=3)), Point(x=0, y=0), False),
(Vector(start=Point(x=1, y=1), end=Point(x=1, y=3)), Point(x=1, y=4), False),
(Vector(start=Point(x=1, y=1), end=Point(x=1, y=3)), Point(x=2, y=4), True),
(Vector(start=Point(x=1, y=3), end=Point(x=1, y=1)), Point(x=0, y=0), True),
(Vector(start=Point(x=1, y=3), end=Point(x=1, y=1)), Point(x=1, y=4), False),
(Vector(start=Point(x=1, y=3), end=Point(x=1, y=1)), Point(x=2, y=4), False),
]
)
def test_vector_is_in(
vector: Vector,
point: Point,
expected_result: bool
) -> None:
result = vector.is_in(point=point)
assert result == expected_result
View File
+34
View File
@@ -0,0 +1,34 @@
from contextlib import ExitStack as DoesNotRaise
from typing import Optional
import pytest
from supervision.draw.color import Color
@pytest.mark.parametrize(
'color_hex, expected_result, exception',
[
('fff', Color.white(), DoesNotRaise()),
('#fff', Color.white(), DoesNotRaise()),
('ffffff', Color.white(), DoesNotRaise()),
('#ffffff', Color.white(), DoesNotRaise()),
('f00', Color.red(), DoesNotRaise()),
('0f0', Color.green(), DoesNotRaise()),
('00f', Color.blue(), DoesNotRaise()),
('#808000', Color(r=128, g=128, b=0), DoesNotRaise()),
('', None, pytest.raises(ValueError)),
('00', None, pytest.raises(ValueError)),
('0000', None, pytest.raises(ValueError)),
('0000000', None, pytest.raises(ValueError)),
('ffg', None, pytest.raises(ValueError)),
]
)
def test_color_from_hex(
color_hex,
expected_result: Optional[Color],
exception: Exception
) -> None:
with exception:
result = Color.from_hex(color_hex=color_hex)
assert result == expected_result