33 lines
822 B
Python
33 lines
822 B
Python
import tkinter as tk
|
|
from PIL import Image, ImageTk
|
|
|
|
|
|
def on_click(event):
|
|
# 打印格式直接就是你代码里需要的 [x, y]
|
|
print(f"[{event.x}, {event.y}]")
|
|
|
|
|
|
def start_picker(image_path):
|
|
root = tk.Tk()
|
|
root.title("点击获取坐标")
|
|
|
|
|
|
img = Image.open(image_path)
|
|
tk_img = ImageTk.PhotoImage(img)
|
|
|
|
canvas = tk.Canvas(root, width=img.width, height=img.height)
|
|
canvas.pack()
|
|
canvas.create_image(0, 0, anchor=tk.NW, image=tk_img)
|
|
|
|
# 绑定左键点击
|
|
canvas.bind("<Button-1>", on_click)
|
|
|
|
print("程序已启动。点击图片,坐标会显示在下方控制台:")
|
|
root.mainloop()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# 填入你的图片路径
|
|
IMAGE_PATH = "/mnt/data/workspace/Code/aida_seg_anything/utils/1767859286.231138.png"
|
|
start_picker(IMAGE_PATH)
|