1818
1919#function to calculate minimum distance from all colors and get the most matching color
2020def get_color_name (R ,G ,B ):
21- minimum = 1000
21+ minimum = 10000
2222 for i in range (len (df )):
2323 d = abs (R - int (df .loc [i , 'R' ])) + abs (G - int (df .loc [i , 'G' ])) + abs (B - int (df .loc [i , 'B' ]))
2424 if d <= minimum :
25+ minimum = d
2526 cname = df .loc [i , 'color_name' ]
2627
2728 return cname
2829
2930#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 ):
3132 if event == cv2 .EVENT_LBUTTONDBLCLK :
3233 global clicked , r , g , b , xpos , ypos
3334 clicked = True
@@ -54,8 +55,9 @@ def draw_function(event, x, y, flags, params):
5455 cv2 .putText (img , text , (50 ,50 ), 2 , 0.8 , (255 , 255 , 255 ), 2 , cv2 .LINE_AA )
5556
5657 # For very light colours we will display text in black colour
57- if r + g + b >= 600 :
58+ if ( r + g + b >= 600 ) :
5859 cv2 .putText (img , text , (50 , 50 ), 2 , 0.8 , (0 , 0 , 0 ), 2 , cv2 .LINE_AA )
60+ clicked = False
5961
6062 # Break the loop when user hits 'esc' key
6163 if cv2 .waitKey (20 ) & 0xFF == 27 :
0 commit comments