在图片处理过程中,有时候我们想要确定图片中某一像素的坐标,可以通过下面方法得到。点击运行程序,用鼠标点击我们想要获取坐标的区域,即可获得其坐标。结束方式是,敲击键盘“q”,回车,即可结束程序。
# -*- coding: utf-8 -*-"""Created on Mon Jan 10 13:58:57 @author: 2540817538(有问题联系此QQ)"""import cv2img=cv2.imread('C:/Users/25408/Desktop/p1.jpg')def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):if event == cv2.EVENT_LBUTTONDOWN:xy = "%d,%d" % (x, y)print(x,y)cv2.circle(img, (x, y), 2, (0, 0, 255))cv2.putText(img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN,1.0, (0,0,255))cv2.imshow("image", img)cv2.namedWindow("image")cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)while(1):cv2.imshow("image", img)key = cv2.waitKey(5) & 0xFFif key == ord('q'):breakcv2.destroyAllWindows()
运行示例:
如果觉得《Python获取图像中像素点坐标》对你有帮助,请点赞、收藏,并留下你的观点哦!