Icon annotator example

This commit is contained in:
LinasKo
2024-08-26 23:53:54 +03:00
parent 317485b122
commit 15a192c63a
2 changed files with 32 additions and 9 deletions
+27
View File
@@ -316,6 +316,33 @@ status: new
</div>
=== "Icon"
```python
import supervision as sv
image = ...
detections = sv.Detections(...)
icon_paths = [
"<ICON_PATH>"
for _ in detections
]
icon_annotator = sv.IconAnnotator()
annotated_frame = icon_annotator.annotate(
scene=image.copy(),
detections=detections,
icon_path=icon_paths
)
```
<div class="result" markdown>
![icon-annotator-example](https://media.roboflow.com/supervision-annotator-examples/icon-annotator-example.png){ align=center width="800" }
</div>
=== "Crop"
```python
+5 -9
View File
@@ -1448,16 +1448,10 @@ class IconAnnotator(BaseAnnotator):
image = ...
detections = sv.Detections(...)
icon_paths = []
for class_name in detections.data["class_name"]:
if class_name == "cat":
icon_paths.append("cat.png")
elif class_id == "dog":
icon_paths.append("dog.png")
else:
icon_paths.append("")
available_icons = ["roboflow.png", "lenny.png"]
icon_paths = [np.random.choice(available_icons) for _ in detections]
icon_annotator = sv.IconAnnotator(icon_resolution_wh=(64, 64))
icon_annotator = sv.IconAnnotator()
annotated_frame = icon_annotator.annotate(
scene=image.copy(),
detections=detections,
@@ -1465,6 +1459,8 @@ class IconAnnotator(BaseAnnotator):
)
```
![icon-annotator-example](https://media.roboflow.com/
supervision-annotator-examples/icon-annotator-example.png)
"""
assert isinstance(scene, np.ndarray)
if isinstance(icon_path, list) and len(icon_path) != len(detections):