import cv2 #引用opencv import numpy as np #图片路径 img = cv2.imread('Images\CAD2.png') a =[] b = [] counts=0
#生成序号方法 def fun(): global counts#添加全局生声明 counts +=1 return counts
#序号标注方法 def on_EVENT_LBUTTONDOWN(event, x, y,flags, param): if event == cv2.EVENT_LBUTTONDOWN: #坐标字符 xy = "%d,%d" % (x, y)
#x坐标值赋值给a a.append(x)
#y坐标值赋值给b b.append(y) # cv2.circle(img, (x, y), 1, (0, 0, 255), thickness=-1) ##绘字(putText) #参数1:待绘制的图像 #参数2:待绘制的文字 #参数3:左上角坐标 #参数4:字体 #参数5:字体大小 #参数6:字体颜色 #参数7:字体粗细 ## cv2.putText(img,str(fun()), (x, y), cv2.FONT_HERSHEY_PLAIN, 1.3, (0, 0, 225), thickness=2)
#显示图片 cv2.imshow("image", img) #弹窗标题 cv2.namedWindow("image")
#点击触发事件 cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)
#显示图片
cv2.imshow("image", img)
#无限等待
cv2.waitKey(0)
print(a[0],b[0])
标签:img,python,image,cv2,参数,序号,counts,左键 From: https://www.cnblogs.com/gzb1/p/16910407.html