在某些时候,对于图片像处理任务需要人工标记。通过该例子功能:鼠标点击后,生成坐标位置可打印到控制台供后续使用。比较方便。
import cv2 import numpy as np # 全局变量 points = [] image = None def click_event(event, x, y, flags, param): global points, image if event == cv2.EVENT_LBUTTONDOWN: points.append((x, y)) cv2.circle(image, (x, y), 5, (0, 0, 255), -1) cv2.imshow('image', image) print(f"Point marked at: ({x}, {y})") def main(image_path): global image image = cv2.imread(image_path) # 调整图像大小 (不经过此步骤都是原图) # width1, height1 = 2300, 1500 # image = cv2.resize(image, (width1, height1)) cv2.imshow('image', image) cv2.setMouseCallback('image', click_event) print("Click on the corners of the grid. Press 'q' to quit and save points.")