如何根据颜色范围检查RGB颜色?

ssh*_*270 1 python rgb

我正在编写一个python脚本,需要在其中检查以下三种颜色的颜色代码:红色,黄色和绿色:

if (255,255,255)  is in green range:
    print("green")
else if (255,255,255)  is in yellow range:
    print("yellow")
else if (255,255,255)  is in red range:
    print("red")
else:
    print("none")
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是如何查看它is in yellow range

任何建议将不胜感激。

编辑

下图代表了我对黄色,绿色和红色的感觉:

在此处输入图片说明

Art*_*Art 6

我只是在终端上破解了以下解决方案,虽然不是很干净,但希望您能理解。

TARGET_COLORS = {"Red": (255, 0, 0), "Yellow": (255, 255, 0), "Green": (0, 255, 0)}

def color_difference (color1, color2):
    return sum([abs(component1-component2) for component1, component2 in zip(color1, color2)])

my_color = (123, 234, 100)

differences = [[color_difference(my_color, target_value), target_name] for target_name, target_value in TARGET_COLORS.items()]
differences.sort()  # sorted by the first element of inner lists
my_color_name = differences[0][1]

print(my_color_name)
Run Code Online (Sandbox Code Playgroud)

数字,my_color = (123, 234, 100)最接近的匹配是绿色:)