import cv2
import sys, os
def OnMouse(event, x, y, flags, param):
#EVENT_LBUTTONDOWN 左键点击
if event == cv2.EVENT_LBUTTONDOWN:
pts_2d.append([x, y])
cv2.circle(img, (x, y), 1, (0, 255, 0), -1)
# # # # # # # # # # #
if __name__ == '__main__':
index = sys.argv[1]
pts_2d = []
img_path = os.path.join('test.jpg')
img = cv2.imread(img_path)
cv2.namedWindow('image')
#setMouseCallback 用来处理鼠标动作的函数
#当鼠标事件触发时,OnMouse()回调函数会被执行
cv2.setMouseCallback('image',OnMouse)
while 1:
cv2.imshow("image", img)
k = cv2.waitKey(1)
if k == 27:
break
print(pts_2d)
Python 获取图片上点的坐标
最新推荐文章于 2024-07-12 11:07:08 发布