opencv查看图像的任意像素位置、RGB值与HSV值等
在windows系统下,运行如下的python代码,可以直接查看图片的pixel值,BGR值,GRAY值,HSV值;
# -*- coding:utf-8 -*-
import cv2
img = cv2.imread('11_13/120002.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
def mouse_click(event, x, y, flags, para):
if event == cv2.EVENT_LBUTTONDOWN: # 左边鼠标点击
print('PIX:', x, y)
print("BGR:", img[y, x])
print("GRAY:", gray[y, x])
print("HSV:", hsv[y, x])
if __name__ == '__main__':
cv2.namedWindow("img")
cv2.setMouseCallback("img", mouse_click)
while True:
cv2.imshow('img', img)
if cv2.waitKey() == ord('q'):
break
cv2.destroyAllWindows()
附一张opencv下HSV范围图片: