本文整理汇总了Python中colorsys.hsv_to_rgb方法的典型用法代码示例。如果您正苦于以下问题:Python colorsys.hsv_to_rgb方法的具体用法?Python colorsys.hsv_to_rgb怎么用?Python colorsys.hsv_to_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类colorsys
的用法示例。
在下文中一共展示了colorsys.hsv_to_rgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_unique_color_float
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def create_unique_color_float(tag, hue_step=0.41):
"""Create a unique RGB color code for a given track id (tag).
The color code is generated in HSV color space by moving along the
hue angle and gradually changing the saturation.
Parameters
----------
tag : int
The unique target identifying tag.
hue_step : float
Difference between two neighboring color codes in HSV space (more
specifically, the distance in hue channel).
Returns
-------
(float, float, float)
RGB color code in range [0, 1]
"""
h, v = (tag * hue_step) % 1, 1. - (int(tag * hue_step) % 4) / 5.
r, g, b = colorsys.hsv_to_rgb(h, 1., v)
return r, g, b
示例2: generate
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def generate(self):
model_path = os.path.expanduser(self.model_path)
assert model_path.endswith('.h5'), 'Keras model must be a .h5 file.'
self.yolo_model = load_model(model_path, compile=False)
print('{} model, anchors, and classes loaded.'.format(model_path))
# Generate colors for drawing bounding boxes.
hsv_tuples = [(x / len(self.class_names), 1., 1.)
for x in range(len(self.class_names))]
self.colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples))
self.colors = list(
map(lambda x: (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)),
self.colors))
random.seed(10101) # Fixed seed for consistent colors across runs.
random.shuffle(self.colors) # Shuffle colors to decorrelate adjacent classes.
random.seed(None) # Reset seed to default.
# Generate output tensor targets for filtered bounding boxes.
self.input_image_shape = K.placeholder(shape=(2, ))
boxes, scores, classes = yolo_eval(self.yolo_model.output, self.anchors,
len(self.class_names), self.input_image_shape,
score_threshold=self.score, iou_threshold=self.iou)
return boxes, scores, classes
示例3: set_brightness
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def set_brightness(channel, br):
global status
if channel == 'all':
for ch in status['colour']:
c = status['colour'][ch]
r, g, b = c
h, s, v = rgb_to_hsv(r, g, b)
v = int(br) / 100.0
r, g, b = [int(c * 255) for c in hsv_to_rgb(h, s, v)]
status['colour'][ch] = [r, g, b]
if not all(status['state'].values()) == 0:
mote_on(status)
else:
c = status['colour'][int(channel)]
r, g, b = c
h, s, v = rgb_to_hsv(r, g, b)
v = int(br) / 100.0
r, g, b = [int(c * 255) for c in hsv_to_rgb(h, s, v)]
status['colour'][int(channel)] = [r, g, b]
if not status['state'][int(channel)] == 0:
mote_on(status)
return jsonify(status)
## Returns the current API version to the requester
示例4: test_hsv_values
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def test_hsv_values(self):
values = [
# rgb, hsv
((0.0, 0.0, 0.0), ( 0 , 0.0, 0.0)), # black
((0.0, 0.0, 1.0), (4./6., 1.0, 1.0)), # blue
((0.0, 1.0, 0.0), (2./6., 1.0, 1.0)), # green
((0.0, 1.0, 1.0), (3./6., 1.0, 1.0)), # cyan
((1.0, 0.0, 0.0), ( 0 , 1.0, 1.0)), # red
((1.0, 0.0, 1.0), (5./6., 1.0, 1.0)), # purple
((1.0, 1.0, 0.0), (1./6., 1.0, 1.0)), # yellow
((1.0, 1.0, 1.0), ( 0 , 0.0, 1.0)), # white
((0.5, 0.5, 0.5), ( 0 , 0.0, 0.5)), # grey
]
for (rgb, hsv) in values:
self.assertTripleEqual(hsv, colorsys.rgb_to_hsv(*rgb))
self.assertTripleEqual(rgb, colorsys.hsv_to_rgb(*hsv))
示例5: rainbowLights
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def rainbowLights(r=5, n=100, freq=2, energy=0.1):
for i in range(n):
t = float(i)/float(n)
pos = (r*sin(tau*t), r*cos(tau*t), r*sin(freq*tau*t))
# Create lamp
bpy.ops.object.add(type='LAMP', location=pos)
obj = bpy.context.object
obj.data.type = 'POINT'
# Apply gamma correction for Blender
color = tuple(pow(c, 2.2) for c in colorsys.hsv_to_rgb(t, 0.6, 1))
# Set HSV color and lamp energy
obj.data.color = color
obj.data.energy = energy
示例6: __set_fill_color
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def __set_fill_color(self, style_name, number, count):
if self.shuffle_colors:
number = int(number * (count + 1) / int(pow(count, 0.5))) % count
(r, g, b) = colorsys.hsv_to_rgb((number + 1) / count, .20, 1.0)
(r, g, b) = int(255 * r), int(255 * g), int(255 * b)
style_sheet = self.doc.get_style_sheet()
draw_style = style_sheet.get_draw_style(style_name)
draw_style.set_fill_color((r, g, b))
style_sheet.add_draw_style(style_name, draw_style)
self.doc.set_style_sheet(style_sheet)
#------------------------------------------------------------------------
#
# FamilyTreeOptions
#
#------------------------------------------------------------------------
示例7: generate_colors
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def generate_colors():
"""
Generate random colors.
To get visually distinct colors, generate them in HSV space then
convert to RGB.
"""
import colorsys
N = 30
brightness = 0.7
hsv = [(i / N, 1, brightness) for i in range(N)]
colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv))
perm = [15, 13, 25, 12, 19, 8, 22, 24, 29, 17, 28, 20, 2, 27, 11, 26, 21, 4, 3, 18, 9, 5, 14, 1, 16, 0, 23, 7,
6, 10]
colors = [colors[idx] for idx in perm]
del colors[::2]
return colors
示例8: generate_colors
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def generate_colors():
"""
Generate random colors.
To get visually distinct colors, generate them in HSV space then
convert to RGB.
"""
N = 30
brightness = 0.7
hsv = [(i / N, 1, brightness) for i in range(N)]
colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv))
perm = [15, 13, 25, 12, 19, 8, 22, 24, 29, 17, 28, 20, 2, 27, 11, 26, 21, 4, 3, 18, 9, 5, 14, 1, 16, 0, 23, 7, 6,
10]
colors = [colors[idx] for idx in perm]
return colors
# from https://github.com/matterport/Mask_RCNN/blob/master/mrcnn/visualize.py
示例9: generate_colors
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def generate_colors():
"""
Generate random colors.
To get visually distinct colors, generate them in HSV space then
convert to RGB.
"""
N = 30
brightness = 0.7
hsv = [(i / N, 1, brightness) for i in range(N)]
colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv))
perm = [15, 13, 25, 12, 19, 8, 22, 24, 29, 17, 28, 20, 2, 27, 11, 26, 21, 4, 3, 18, 9, 5, 14, 1, 16, 0, 23, 7, 6, 10]
colors = [colors[idx] for idx in perm]
return colors
# from https://github.com/matterport/Mask_RCNN/blob/master/mrcnn/visualize.py
示例10: set_pixel_hsv
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def set_pixel_hsv(x, y, h, s=1.0, v=1.0):
"""Set a single pixel to a colour using HSV.
:param x: Horizontal position from 0 to 15
:param y: Veritcal position from 0 to 15
:param h: Hue from 0.0 to 1.0 ( IE: degrees around hue wheel/360.0 )
:param s: Saturation from 0.0 to 1.0
:param v: Value (also known as brightness) from 0.0 to 1.0
"""
r, g, b = [int(n * 255) for n in colorsys.hsv_to_rgb(h, s, v)]
set_pixel(x, y, r, g, b)
示例11: RGB_to_RG
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def RGB_to_RG(rgb):
if rgb[2] != 0:
color = list(colorsys.rgb_to_hsv(rgb[0], rgb[1], rgb[2]))
color[0] = color[0] * (106/330)
color = list(colorsys.hsv_to_rgb(color[0], color[1], color[2]))
color = [round(x) for x in color]
for x in range(2):
color[x] = round(color[x])
return color[:2] + [0]
else:
return rgb
示例12: to_rgb
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def to_rgb(hsv):
"""Converts a color from HSV to a hex RGB.
HSV should be in range 0..1, though hue wraps around. Output is a
hexadecimal color value as used by CSS, HTML and SVG"""
r, g, b = [int(min(255, max(0, component * 256)))
for component in colorsys.hsv_to_rgb(*hsv)]
return "%02x%02x%02x" % (r, g, b)
示例13: random_colors
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def random_colors(N, bright=True):
"""
Generate random colors.
To get visually distinct colors, generate them in HSV space then
convert to RGB.
"""
brightness = 1.0 if bright else 0.7
hsv = np.random.rand(N, 3)
hsv[:, 1] = 1
hsv[:, 2] = brightness
# hsv = [(i / N, 1, brightness) for i in range(N)]
colors = list(map(lambda c: colorsys.hsv_to_rgb(*c), hsv))
random.shuffle(colors)
return colors
示例14: make_dark_color
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def make_dark_color(h):
h = h % 1.
s = 0.95
v = 0.8
return colorsys.hsv_to_rgb(h,0.9+s*.1,v)
示例15: ring_colors
# 需要导入模块: import colorsys [as 别名]
# 或者: from colorsys import hsv_to_rgb [as 别名]
def ring_colors(self) -> List[Tuple[float, float, float]]:
return [
colorsys.hsv_to_rgb(
(self.current_fraction + led / self.lights.ring.LED_COUNT) % 1, 1, 1
)
for led in range(self.lights.ring.LED_COUNT)
]