From 515c63e477c4d1532d87cf78ecb58b2dfc25d284 Mon Sep 17 00:00:00 2001 From: Ifeanyi Idiaye <72707830+Ifeanyi55@users.noreply.github.com> Date: Thu, 9 Oct 2025 19:26:06 +0100 Subject: [PATCH 1/2] Created image_annotate.py --- computer_vision/image_annotate.py | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 computer_vision/image_annotate.py diff --git a/computer_vision/image_annotate.py b/computer_vision/image_annotate.py new file mode 100644 index 000000000000..68df69fa43a0 --- /dev/null +++ b/computer_vision/image_annotate.py @@ -0,0 +1,39 @@ +import supervision as sv +from ultralytics import YOLO +from PIL import Image +import numpy as np +import cv2 + +def image_annotate(image:str) -> Image.Image: + # load the input image + image = cv2.imread(image) + + # load pre-trained vision model + model = YOLO("yolo12s.pt") + + # run object detection on the image + result = model(image)[0] + + # convert YOLO output to a Supervision-compatible detections format + detections = sv.Detections.from_ultralytics(result) + + # initialize a box annotator for drawing detection bounding boxes + box_annotator = sv.BoxAnnotator() + + # annotate the image with detected objects + annotated_image = box_annotator.annotate( + scene=image.copy(), + detections=detections) + + # convert BGR to RGB for correct display + annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB) + + # convert the annotated NumPy array (RGB) to a PIL Image object + annotated_pil_image = Image.fromarray(annotated_image_rgb) + + # return annotated image + return annotated_pil_image + +if __name__ == "__main__": + annotate_img = image_annotate("/content/sample_data/Furry.png") + annotate_img.show() From d4a50412a114aa37d98d43fefe35fa36fa5e7a1a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 9 Oct 2025 18:27:51 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- computer_vision/image_annotate.py | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/computer_vision/image_annotate.py b/computer_vision/image_annotate.py index 68df69fa43a0..459aedf082c5 100644 --- a/computer_vision/image_annotate.py +++ b/computer_vision/image_annotate.py @@ -4,36 +4,36 @@ import numpy as np import cv2 -def image_annotate(image:str) -> Image.Image: - # load the input image - image = cv2.imread(image) - # load pre-trained vision model - model = YOLO("yolo12s.pt") +def image_annotate(image: str) -> Image.Image: + # load the input image + image = cv2.imread(image) - # run object detection on the image - result = model(image)[0] + # load pre-trained vision model + model = YOLO("yolo12s.pt") - # convert YOLO output to a Supervision-compatible detections format - detections = sv.Detections.from_ultralytics(result) + # run object detection on the image + result = model(image)[0] - # initialize a box annotator for drawing detection bounding boxes - box_annotator = sv.BoxAnnotator() + # convert YOLO output to a Supervision-compatible detections format + detections = sv.Detections.from_ultralytics(result) - # annotate the image with detected objects - annotated_image = box_annotator.annotate( - scene=image.copy(), - detections=detections) - - # convert BGR to RGB for correct display - annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB) + # initialize a box annotator for drawing detection bounding boxes + box_annotator = sv.BoxAnnotator() - # convert the annotated NumPy array (RGB) to a PIL Image object - annotated_pil_image = Image.fromarray(annotated_image_rgb) + # annotate the image with detected objects + annotated_image = box_annotator.annotate(scene=image.copy(), detections=detections) + + # convert BGR to RGB for correct display + annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB) + + # convert the annotated NumPy array (RGB) to a PIL Image object + annotated_pil_image = Image.fromarray(annotated_image_rgb) + + # return annotated image + return annotated_pil_image - # return annotated image - return annotated_pil_image if __name__ == "__main__": - annotate_img = image_annotate("/content/sample_data/Furry.png") - annotate_img.show() + annotate_img = image_annotate("/content/sample_data/Furry.png") + annotate_img.show()