superiorvision 0.30.0.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. superiorvision/__init__.py +19 -0
  2. superiorvision-0.30.0.dev0.dist-info/METADATA +398 -0
  3. superiorvision-0.30.0.dev0.dist-info/RECORD +96 -0
  4. superiorvision-0.30.0.dev0.dist-info/WHEEL +5 -0
  5. superiorvision-0.30.0.dev0.dist-info/licenses/LICENSE.md +9 -0
  6. superiorvision-0.30.0.dev0.dist-info/top_level.txt +2 -0
  7. supervision/__init__.py +318 -0
  8. supervision/annotators/__init__.py +0 -0
  9. supervision/annotators/base.py +21 -0
  10. supervision/annotators/core.py +3551 -0
  11. supervision/annotators/utils.py +541 -0
  12. supervision/assets/__init__.py +4 -0
  13. supervision/assets/downloader.py +166 -0
  14. supervision/assets/list.py +84 -0
  15. supervision/classification/__init__.py +0 -0
  16. supervision/classification/core.py +216 -0
  17. supervision/config.py +13 -0
  18. supervision/dataset/__init__.py +0 -0
  19. supervision/dataset/core.py +1313 -0
  20. supervision/dataset/formats/__init__.py +0 -0
  21. supervision/dataset/formats/coco.py +708 -0
  22. supervision/dataset/formats/createml.py +331 -0
  23. supervision/dataset/formats/labelme.py +405 -0
  24. supervision/dataset/formats/pascal_voc.py +449 -0
  25. supervision/dataset/formats/yolo.py +502 -0
  26. supervision/dataset/utils.py +265 -0
  27. supervision/detection/__init__.py +0 -0
  28. supervision/detection/compact_mask.py +1927 -0
  29. supervision/detection/core.py +3864 -0
  30. supervision/detection/line_zone.py +924 -0
  31. supervision/detection/overlap_filter.py +426 -0
  32. supervision/detection/tensor_utils.py +1596 -0
  33. supervision/detection/tensor_views.py +48 -0
  34. supervision/detection/tools/__init__.py +0 -0
  35. supervision/detection/tools/csv_sink.py +242 -0
  36. supervision/detection/tools/inference_slicer.py +776 -0
  37. supervision/detection/tools/json_sink.py +215 -0
  38. supervision/detection/tools/polygon_zone.py +266 -0
  39. supervision/detection/tools/smoother.py +218 -0
  40. supervision/detection/tools/transformers.py +265 -0
  41. supervision/detection/utils/__init__.py +12 -0
  42. supervision/detection/utils/_typing.py +11 -0
  43. supervision/detection/utils/boxes.py +510 -0
  44. supervision/detection/utils/converters.py +830 -0
  45. supervision/detection/utils/internal.py +806 -0
  46. supervision/detection/utils/iou_and_nms.py +1606 -0
  47. supervision/detection/utils/masks.py +625 -0
  48. supervision/detection/utils/polygons.py +128 -0
  49. supervision/detection/utils/vlms.py +97 -0
  50. supervision/detection/vlm.py +945 -0
  51. supervision/draw/__init__.py +0 -0
  52. supervision/draw/base.py +14 -0
  53. supervision/draw/color.py +598 -0
  54. supervision/draw/utils.py +527 -0
  55. supervision/geometry/__init__.py +0 -0
  56. supervision/geometry/core.py +208 -0
  57. supervision/geometry/utils.py +54 -0
  58. supervision/key_points/__init__.py +0 -0
  59. supervision/key_points/annotators.py +997 -0
  60. supervision/key_points/core.py +1506 -0
  61. supervision/key_points/skeletons.py +2646 -0
  62. supervision/keypoint/__init__.py +13 -0
  63. supervision/keypoint/annotators.py +13 -0
  64. supervision/keypoint/core.py +8 -0
  65. supervision/metrics/__init__.py +40 -0
  66. supervision/metrics/core.py +74 -0
  67. supervision/metrics/detection.py +1632 -0
  68. supervision/metrics/f1_score.py +815 -0
  69. supervision/metrics/mean_average_precision.py +1723 -0
  70. supervision/metrics/mean_average_recall.py +734 -0
  71. supervision/metrics/precision.py +815 -0
  72. supervision/metrics/recall.py +774 -0
  73. supervision/metrics/utils/__init__.py +0 -0
  74. supervision/metrics/utils/matching.py +56 -0
  75. supervision/metrics/utils/object_size.py +256 -0
  76. supervision/metrics/utils/utils.py +9 -0
  77. supervision/py.typed +0 -0
  78. supervision/tracker/__init__.py +5 -0
  79. supervision/tracker/byte_tracker/__init__.py +0 -0
  80. supervision/tracker/byte_tracker/core.py +448 -0
  81. supervision/tracker/byte_tracker/kalman_filter.py +186 -0
  82. supervision/tracker/byte_tracker/matching.py +211 -0
  83. supervision/tracker/byte_tracker/single_object_track.py +194 -0
  84. supervision/tracker/byte_tracker/utils.py +34 -0
  85. supervision/utils/__init__.py +0 -0
  86. supervision/utils/conversion.py +223 -0
  87. supervision/utils/deprecate.py +54 -0
  88. supervision/utils/file.py +209 -0
  89. supervision/utils/image.py +988 -0
  90. supervision/utils/internal.py +209 -0
  91. supervision/utils/iterables.py +103 -0
  92. supervision/utils/logger.py +61 -0
  93. supervision/utils/notebook.py +124 -0
  94. supervision/utils/tensor.py +362 -0
  95. supervision/utils/video.py +533 -0
  96. supervision/validators/__init__.py +379 -0
@@ -0,0 +1,208 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from enum import Enum
5
+ from math import sqrt
6
+
7
+
8
+ class Position(Enum):
9
+ """
10
+ Enum representing the position of an anchor point.
11
+ """
12
+
13
+ CENTER = "CENTER"
14
+ CENTER_LEFT = "CENTER_LEFT"
15
+ CENTER_RIGHT = "CENTER_RIGHT"
16
+ TOP_CENTER = "TOP_CENTER"
17
+ TOP_LEFT = "TOP_LEFT"
18
+ TOP_RIGHT = "TOP_RIGHT"
19
+ BOTTOM_LEFT = "BOTTOM_LEFT"
20
+ BOTTOM_CENTER = "BOTTOM_CENTER"
21
+ BOTTOM_RIGHT = "BOTTOM_RIGHT"
22
+ CENTER_OF_MASS = "CENTER_OF_MASS"
23
+
24
+ @classmethod
25
+ def list(cls) -> list[str]:
26
+ """Return all position values in their definition order."""
27
+ return [position.value for position in cls]
28
+
29
+
30
+ @dataclass
31
+ class Point:
32
+ """
33
+ Represents a point in 2D space.
34
+
35
+ Attributes:
36
+ x: The x-coordinate of the point.
37
+ y: The y-coordinate of the point.
38
+
39
+ Example:
40
+ ```pycon
41
+ >>> from supervision.geometry.core import Point
42
+ >>> point = Point(x=10.0, y=20.0)
43
+ >>> point.as_xy_int_tuple()
44
+ (10, 20)
45
+ >>> point.as_xy_float_tuple()
46
+ (10.0, 20.0)
47
+
48
+ ```
49
+ """
50
+
51
+ x: float
52
+ y: float
53
+
54
+ def as_xy_int_tuple(self) -> tuple[int, int]:
55
+ """
56
+ Returns the point as a tuple of integers.
57
+
58
+ Returns:
59
+ The point as (x, y) integers.
60
+ """
61
+ return int(self.x), int(self.y)
62
+
63
+ def as_xy_float_tuple(self) -> tuple[float, float]:
64
+ """
65
+ Returns the point as a tuple of floats.
66
+
67
+ Returns:
68
+ The point as (x, y) floats.
69
+ """
70
+ return self.x, self.y
71
+
72
+
73
+ @dataclass
74
+ class Vector:
75
+ """
76
+ Represents a vector in 2D space, defined by a start and an end point.
77
+
78
+ Attributes:
79
+ start: The starting point of the vector.
80
+ end: The end point of the vector.
81
+
82
+ Example:
83
+ ```pycon
84
+ >>> from supervision.geometry.core import Point, Vector
85
+ >>> start_point = Point(x=0.0, y=0.0)
86
+ >>> end_point = Point(x=3.0, y=4.0)
87
+ >>> vector = Vector(start=start_point, end=end_point)
88
+ >>> vector.magnitude
89
+ 5.0
90
+ >>> vector.center
91
+ Point(x=1.5, y=2.0)
92
+
93
+ ```
94
+ """
95
+
96
+ start: Point
97
+ end: Point
98
+
99
+ @property
100
+ def magnitude(self) -> float:
101
+ """
102
+ Calculate the magnitude (length) of the vector.
103
+
104
+ Returns:
105
+ The magnitude of the vector.
106
+ """
107
+ dx = self.end.x - self.start.x
108
+ dy = self.end.y - self.start.y
109
+ return sqrt(dx**2 + dy**2)
110
+
111
+ @property
112
+ def center(self) -> Point:
113
+ """
114
+ Calculate the center point of the vector.
115
+
116
+ Returns:
117
+ The center point of the vector.
118
+ """
119
+ return Point(
120
+ x=(self.start.x + self.end.x) / 2,
121
+ y=(self.start.y + self.end.y) / 2,
122
+ )
123
+
124
+ def cross_product(self, point: Point) -> float:
125
+ """
126
+ Calculate the 2D cross product (also known as the vector product or outer
127
+ product) of the vector and a point, treated as vectors in 2D space.
128
+
129
+ Args:
130
+ point: The point to be evaluated, treated as the endpoint of a
131
+ vector originating from the 'start' of the main vector.
132
+
133
+ Returns:
134
+ The scalar value of the cross product. It is positive if 'point'
135
+ lies to the left of the vector (when moving from 'start' to 'end'),
136
+ negative if it lies to the right, and 0 if it is collinear with the
137
+ vector.
138
+ """
139
+ dx_vector = self.end.x - self.start.x
140
+ dy_vector = self.end.y - self.start.y
141
+ dx_point = point.x - self.start.x
142
+ dy_point = point.y - self.start.y
143
+ return (dx_vector * dy_point) - (dy_vector * dx_point)
144
+
145
+
146
+ @dataclass
147
+ class Rect:
148
+ """
149
+ Represents a rectangle in 2D space.
150
+
151
+ Attributes:
152
+ x: The x-coordinate of the top-left corner of the rectangle.
153
+ y: The y-coordinate of the top-left corner of the rectangle.
154
+ width: The width of the rectangle.
155
+ height: The height of the rectangle.
156
+
157
+ Example:
158
+ ```pycon
159
+ >>> from supervision.geometry.core import Rect
160
+ >>> rect = Rect(x=10.0, y=20.0, width=30.0, height=40.0)
161
+ >>> rect.top_left
162
+ Point(x=10.0, y=20.0)
163
+ >>> rect.bottom_right
164
+ Point(x=40.0, y=60.0)
165
+ >>> rect.as_xyxy_int_tuple()
166
+ (10, 20, 40, 60)
167
+
168
+ ```
169
+ """
170
+
171
+ x: float
172
+ y: float
173
+ width: float
174
+ height: float
175
+
176
+ @classmethod
177
+ def from_xyxy(cls, xyxy: tuple[float, float, float, float]) -> Rect:
178
+ """Create a rectangle from `(x_min, y_min, x_max, y_max)` coordinates."""
179
+ x1, y1, x2, y2 = xyxy
180
+ return cls(x=x1, y=y1, width=x2 - x1, height=y2 - y1)
181
+
182
+ @property
183
+ def top_left(self) -> Point:
184
+ """Return the top-left corner as a `Point`."""
185
+ return Point(x=self.x, y=self.y)
186
+
187
+ @property
188
+ def bottom_right(self) -> Point:
189
+ """Return the bottom-right corner as a `Point`."""
190
+ return Point(x=self.x + self.width, y=self.y + self.height)
191
+
192
+ def pad(self, padding: int) -> Rect:
193
+ """Return a rectangle expanded by `padding` pixels on every side."""
194
+ return Rect(
195
+ x=self.x - padding,
196
+ y=self.y - padding,
197
+ width=self.width + 2 * padding,
198
+ height=self.height + 2 * padding,
199
+ )
200
+
201
+ def as_xyxy_int_tuple(self) -> tuple[int, int, int, int]:
202
+ """Return `(x_min, y_min, x_max, y_max)` coordinates as integers."""
203
+ return (
204
+ int(self.x),
205
+ int(self.y),
206
+ int(self.x + self.width),
207
+ int(self.y + self.height),
208
+ )
@@ -0,0 +1,54 @@
1
+ import numpy as np
2
+ import numpy.typing as npt
3
+
4
+ from supervision.geometry.core import Point
5
+
6
+
7
+ def get_polygon_center(polygon: npt.NDArray[np.float64]) -> Point:
8
+ """
9
+ Calculate the center of a polygon. The center is calculated as the center
10
+ of the solid figure formed by the points of the polygon
11
+
12
+ Args:
13
+ polygon: A 2-dimensional numpy ndarray representing the vertices of the
14
+ polygon.
15
+
16
+ Returns:
17
+ The center of the polygon, represented as a Point object with x and y
18
+ attributes.
19
+
20
+ Raises:
21
+ ValueError: If the polygon has no vertices.
22
+
23
+ Examples:
24
+ ```pycon
25
+ >>> import numpy as np
26
+ >>> import supervision as sv
27
+ >>> polygon = np.array([[0, 0], [0, 2], [2, 2], [2, 0]])
28
+ >>> center = sv.get_polygon_center(polygon=polygon)
29
+ >>> float(center.x)
30
+ 1.0
31
+ >>> float(center.y)
32
+ 1.0
33
+
34
+ ```
35
+ """
36
+
37
+ # This is one of the 3 candidate algorithms considered for centroid calculation.
38
+ # For a more detailed discussion, see PR #1084 and commit eb33176
39
+
40
+ if len(polygon) == 0:
41
+ raise ValueError("Polygon must have at least one vertex.")
42
+
43
+ shift_polygon = np.roll(polygon, -1, axis=0)
44
+ signed_areas = (
45
+ polygon[..., 0] * shift_polygon[..., 1]
46
+ - polygon[..., 1] * shift_polygon[..., 0]
47
+ ) / 2
48
+ if signed_areas.sum() == 0:
49
+ center = np.mean(polygon, axis=0).round()
50
+ return Point(x=center[0], y=center[1])
51
+ centroids = (polygon + shift_polygon) / 3.0
52
+ center = np.average(centroids, axis=0, weights=signed_areas).round()
53
+
54
+ return Point(x=center[0], y=center[1])
File without changes