18
18
19
19
#function to calculate minimum distance from all colors and get the most matching color
20
20
def get_color_name (R ,G ,B ):
21
- minimum = 1000
21
+ minimum = 10000
22
22
for i in range (len (df )):
23
23
d = abs (R - int (df .loc [i , 'R' ])) + abs (G - int (df .loc [i , 'G' ])) + abs (B - int (df .loc [i , 'B' ]))
24
24
if d <= minimum :
25
+ minimum = d
25
26
cname = df .loc [i , 'color_name' ]
26
27
27
28
return cname
28
29
29
30
#function to get x,y coordinates of mouse double click
30
- def draw_function (event , x , y , flags , params ):
31
+ def draw_function (event , x , y , flags , param ):
31
32
if event == cv2 .EVENT_LBUTTONDBLCLK :
32
33
global clicked , r , g , b , xpos , ypos
33
34
clicked = True
@@ -54,8 +55,9 @@ def draw_function(event, x, y, flags, params):
54
55
cv2 .putText (img , text , (50 ,50 ), 2 , 0.8 , (255 , 255 , 255 ), 2 , cv2 .LINE_AA )
55
56
56
57
# For very light colours we will display text in black colour
57
- if r + g + b >= 600 :
58
+ if ( r + g + b >= 600 ) :
58
59
cv2 .putText (img , text , (50 , 50 ), 2 , 0.8 , (0 , 0 , 0 ), 2 , cv2 .LINE_AA )
60
+ clicked = False
59
61
60
62
# Break the loop when user hits 'esc' key
61
63
if cv2 .waitKey (20 ) & 0xFF == 27 :
0 commit comments