Spaces:
Sleeping
Sleeping
import colorsys | |
# Define the categories | |
CATEGORIES = ["info", "table", "part", "surface-all", "GD&T", "zoom", "surface-trie", | |
"3D", "edge", "surface-check", "corner", "surface-ball", "info-table"] | |
# Generate distinct colors for each category | |
def generate_colors(n): | |
colors = [] | |
for i in range(n): | |
# Use HSV color space to generate evenly distributed distinct colors | |
hue = i / n | |
sat = 0.8 + (i % 3) * 0.1 # Vary saturation slightly | |
val = 0.8 + (i % 2) * 0.1 # Vary value slightly | |
# Convert to RGB | |
rgb = colorsys.hsv_to_rgb(hue, sat, val) | |
# Convert to BGR (for OpenCV) and scale to 0-255 | |
bgr = (int(rgb[2] * 255), int(rgb[1] * 255), int(rgb[0] * 255)) | |
colors.append(bgr) | |
return colors | |