-
Notifications
You must be signed in to change notification settings - Fork 0
/
Color Picker.py
30 lines (26 loc) · 1.01 KB
/
Color Picker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#This is one of the assitive programs for the task of onboard object detection.
#It commits to read HSV of any point you click in an image
#You click on any point, the [H, S, V] will be printed out
#2 windows will pop out:
#1st one is initial image, for you to find the object
#2nd one is the "Hue" image, for you to find the value may differ
import cv2
import cv2 as cv
import numpy as np
image = cv.imread("123.jpg")
#transfer color space into HSV
HSV = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
#get postion through mouse event and print [H,S,V] value
def getpos(event,x,y,flags,param):
if event==cv2.EVENT_LBUTTONDOWN:
print(HSV[y,x])
#Show the 1st window, on which you click
cv.namedWindow("image", cv.WINDOW_NORMAL)
cv2.resizeWindow("image", 1200, 900)
cv2.imshow('image',image)
#Show the image in HSV space
cv.namedWindow("imageHSV", cv.WINDOW_NORMAL)
cv2.resizeWindow("imageHSV", 1200, 900)
cv2.imshow("imageHSV",HSV)
cv2.setMouseCallback("image",getpos)
cv2.waitKey(0)#keep showing