# -*- coding: utf-8 -*-
"""
Created on Mon May 7 11:38:45 2018
@author: PC
"""
# -*- coding: utf-8 -*-
import cv2
img= cv2.imread('C:/Users/PC/Desktop/program/skin/Images/1.jpg') #定义图片位置
#img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #转化为灰度图
def onmouse(event, x, y, flags, param): #标准鼠标交互函数
# if event==cv2.EVENT_LBUTTONDBLCLK : #当鼠标点击时
# print("y=",y), print("x=",x), print(img[y,x],"\n") #显示鼠标所在像素的数值,注意像素表示方法和坐标位置的不同
if event==cv2.EVENT_MOUSEMOVE : #当鼠标移动时
print("y=",y, "x=",x, img[y,x],"\n") #显示鼠标所在像素的数值,注意像素表示方法和坐标位置的不同
def main():
cv2.namedWindow("img") #构建窗口
cv2.setMouseCallback("img", onmouse) #回调绑定窗口
while True: #无限循环
cv2.imshow("img",img) #显示图像
if cv2.waitKey() == 27:
cv2.destroyAllWindows() #关闭窗口
break
if __name__ == '__main__': #运行
main()
实时显示图像的BGR值、鼠标位置
猜你喜欢
转载自blog.csdn.net/weixin_39153202/article/details/82425217
今日推荐
周排行