Skip to content

Commit 26af9b5

Browse files
authored
Created image_annotation.py
1 parent 788d95b commit 26af9b5

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# image annotation
2+
import supervision as sv
3+
from ultralytics import YOLO
4+
import cv2
5+
6+
# load the input image
7+
image = cv2.imread("image file path")
8+
9+
# load pre-trained vision model
10+
model = YOLO("yolo12s.pt")
11+
12+
# run object detection on the image
13+
result = model(image)[0]
14+
15+
# convert YOLO output to a Supervision-compatible detections format
16+
detections = sv.Detections.from_ultralytics(result)
17+
18+
# initialize a box annotator for drawing detection bounding boxes
19+
box_annotator = sv.BoxAnnotator()
20+
21+
# annotate image with detected objects
22+
annotated_frame = box_annotator.annotate(
23+
scene=image.copy(),
24+
detections=detections)
25+
26+
# view annotated image
27+
annotated_frame

0 commit comments

Comments
 (0)