import cv2 as cv
import numpy as np
import glob

# load image
BGR_img = cv.imread('sign_photos/slunce/dej_prednost_v_jizde/prednost_v_jizde_8.jpg')

# convert color to HSV
image_HSV = cv.cvtColor(BGR_img, cv.COLOR_BGR2HSV)

# left click mouse button show color HSV values and creates final mask
def click_event(event, x, y, flags, param):
	if event == cv.EVENT_LBUTTONDOWN:
		
		# detected values
		H = image_HSV[y,x,0]
		S = image_HSV[y,x,1]
		V = image_HSV[y,x,2]
		
		v1 = 10
		v2 = 30
		v3 = 80
		
		# lower and upper threshold values
		lower = np.array([H-v1, S-v2, V-v3])
		upper = np.array([H+v1, S+v2, V+v3])
		
		# create mask from detected threshold values
		mask = cv.inRange(image_HSV ,lower, upper)
		
		print(H, S, V) 
		
		cv.imshow('original', BGR_img)
		cv.imshow('mask', mask)

		
cv.imshow('original', BGR_img)        
cv.setMouseCallback("original", click_event)
cv.waitKey(0)
cv.destroyAllWindows      
        
        
        
        
        
        
        
        
        
        
        
        
        
        
