From 28c6edd6b3feea65f2af77314ad151635b362299 Mon Sep 17 00:00:00 2001 From: Timothyxxx <384084775@qq.com> Date: Tue, 28 Nov 2023 00:40:04 +0800 Subject: [PATCH] Add data marker tool --- utils/image_processing/__init__.py | 0 utils/image_processing/point_marking.py | 32 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 utils/image_processing/__init__.py create mode 100644 utils/image_processing/point_marking.py diff --git a/utils/image_processing/__init__.py b/utils/image_processing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/image_processing/point_marking.py b/utils/image_processing/point_marking.py new file mode 100644 index 0000000..8cfd519 --- /dev/null +++ b/utils/image_processing/point_marking.py @@ -0,0 +1,32 @@ +from PIL import Image, ImageDraw + + +def mark_point(image_path: str, x: int, y: int, radius: int = 5, color: str = 'red') -> str: + """ + Mark a point on an image and save the image. + """ + # Load the image + image = Image.open(image_path) + + # Create a draw object + draw = ImageDraw.Draw(image) + + # Draw a small circle to mark the point + draw.ellipse((x - radius, y - radius, x + radius, y + radius), fill=color, outline=color) + + # Save the image with the point marked + marked_image_path = image_path[:-4] + '_marked' + image_path[-4:] + image.save(marked_image_path) + + return marked_image_path + + +if __name__ == '__main__': + image_path = 'chrome_start.png' + x = 100 + y = 200 + radius = 30 + color = 'red' + + marked_image_path = mark_point(image_path, x, y, radius, color) + print(f"Marked image saved to {marked_image_path}") \ No newline at end of file