diff --git a/Official_Tutorial_Python_Codes/2_core/RGB2HSV_converter.py b/Official_Tutorial_Python_Codes/2_core/RGB2HSV_converter.py new file mode 100644 index 0000000..71ed1d1 --- /dev/null +++ b/Official_Tutorial_Python_Codes/2_core/RGB2HSV_converter.py @@ -0,0 +1,28 @@ +#RGB2HSV_converter# +# Gustavo Martin Vela - WebLab Deusto. www.weblab.deusto.es +# gustavo.martin@opendeusto.es + +import colorsys + +def RGB2HSV_converter(R, G, B): + ''' Put your RGB color here and this method return the HSV code of color prepared to use with cv2 library''' + #print "RGB %s %s %s" % (R,G,B) + #print "BGR %s %s %s" % (B,G,R) + R = R / 255.0 + G = G / 255.0 + B = B / 255.0 + #print "RGB %.2f %.2f %.2f" % (R,G,B) + H, S, V = colorsys.rgb_to_hsv(R, G, B) + #print "HSV %.2f %.2f %.2f" % (H,S,V) + H = H * 180 + S = S * 255 + V = V * 255 + #print "HSV %.2f %.2f %.2f" % (H,S,V) + return H, S, V + +# Examples of use +# GOLD Color in RGB +H, S, V = RGB2HSV_converter(255, 215, 0) +print "HSV %.2f %.2f %.2f" % (H,S,V) # HSV 25.29 255.00 255.00 +# GREEN Color in RGB +H, S, V = RGB2HSV_converter(118, 238, 0)