Home Python实现点击图片获取HSV或BGR的值
Post
Cancel

Python实现点击图片获取HSV或BGR的值

单击图片即可得到HSV或BGR的值,代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import cv2

def getposHsv(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        print("HSV is", HSV[y, x])

def getposBgr(event, x, y, flags, param):
    if event == cv2.EVENT_LBUTTONDOWN:
        print("BGR is", image[y, x])

image = cv2.imread('frame_B.jpg')
HSV = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
cv2.imshow("imageHSV", HSV)
cv2.imshow('image', image)
cv2.setMouseCallback("imageHSV", getposHsv)
cv2.setMouseCallback("image", getposBgr)
cv2.waitKey(0)
This post is licensed under CC BY 4.0 by the author.

Python脚本制作coco格式的实例分割数据集

Github合并两个不同的仓库