赞
踩
在图片处理过程中,有时候我们想要确定图片中某一像素的坐标,可以通过下面方法得到。点击运行程序,用鼠标点击我们想要获取坐标的区域,即可获得其坐标。结束方式是,敲击键盘“q”,回车,即可结束程序。
- # -*- coding: utf-8 -*-
- """
- Created on Mon Jan 10 13:58:57 2022
- @author: 2540817538(有问题联系此QQ)
- """
- import cv2
- img=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) & 0xFF
- if key == ord('q'):
- break
- cv2.destroyAllWindows()
运行示例:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。