显示鼠标指定点像素的坐标值和亮度值

2020-03-25  本文已影响0人  求索_700e

import cv2

import numpy as np

img=cv2.imread('./ST5__0.jpg')

#img=cv2.imread('/devdata/90140/thick7exp/test/sss1/outputs/xxx/GJ7948616BKKG9QAM/ST1__0.jpg')

'''

img_ = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# 限制对比度的自适应阈值均衡化             

clahe = cv2.createCLAHE(clipLimit=10.0, tileGridSize=(5, 5))

img = clahe.apply(img_)

'''

def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):

    if event == cv2.EVENT_LBUTTONDOWN:

        v=img[y,x,0]

        vxy = "%d,  %d,%d" % (v, x, y)

        img__=img.copy()

        cv2.circle(img__, (x, y), 1, (255, 0, 0), thickness = -1)

        cv2.putText(img__, vxy, (x, y), cv2.FONT_HERSHEY_PLAIN,

                  2.0, (255,0,0), thickness = 1)

        cv2.imshow("image", img__)

        #cv2.waitKey(0)

cv2.namedWindow("image", cv2.WINDOW_NORMAL)

cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)

while(1):

    cv2.imshow("image", img)

    if cv2.waitKey(0)&0xFF==27:

        break

cv2.destroyAllWindows()

上一篇下一篇

猜你喜欢

热点阅读