Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Official_Tutorial_Python_Codes/2_core/RGB2HSV_converter.py
Original file line number Diff line number Diff line change
@@ -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)