Created
January 5, 2023 11:10
-
-
Save sukhitashvili/d536f815ee12dca32a5b499df6ac19ed to your computer and use it in GitHub Desktop.
Generates N color tuples for opencv-python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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