Skip to content

Instantly share code, notes, and snippets.

@sukhitashvili
Created January 5, 2023 11:10
Show Gist options
  • Save sukhitashvili/d536f815ee12dca32a5b499df6ac19ed to your computer and use it in GitHub Desktop.
Save sukhitashvili/d536f815ee12dca32a5b499df6ac19ed to your computer and use it in GitHub Desktop.
Generates N color tuples for opencv-python
import colorsys
def hsv_to_rgb(h, s, v):
r, g, b = colorsys.hsv_to_rgb(h, s, v)
return [int(255 * i) for i in [r, g, b]]
def get_n_colors(n: int):
"""
Generates n distinct colors
:param n: int
:return: list of color tuples
"""
hue_partition = 1 / (n + 1)
return [hsv_to_rgb(hue_partition * value, 1, 1) for value in range(0, n)]
print("N colors:", get_n_colors(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment