Icon annotator example
This commit is contained in:
@@ -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>
|
||||
|
||||
{ align=center width="800" }
|
||||
|
||||
</div>
|
||||
|
||||
=== "Crop"
|
||||
|
||||
```python
|
||||
|
||||
@@ -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):
|
||||
)
|
||||
```
|
||||
|
||||

|
||||
"""
|
||||
assert isinstance(scene, np.ndarray)
|
||||
if isinstance(icon_path, list) and len(icon_path) != len(detections):
|
||||
|
||||
Reference in New Issue
Block a user