我正在尝试制作一个跟踪程序,该程序拍摄图像并显示具有指定颜色的对象所在的位置:
为此,我现在使用 RGB,但使用它确实很难,所以我想将其转换为色调,以便更容易使用。我正在尝试使用 colorsys,但经过一些研究后,我不知道它想要什么参数以及它提供什么。我尝试使用 colorizer.org 进行匹配,但得到了一些废话。
>>> import colorsys
>>> colorsys.rgb_to_hsv(45,201,18)
(0.3087431693989071, 0.9104477611940298, 201)
colorsys 已经没有按照记录的那样运行,因为 https://docs.python.org/2/library/colorsys.html它表示输出始终是 0 到 1 之间的 float ,但值为 201。这也是不可能的,因为在标准 HSV 中该值介于 0 到 100 之间。
我的问题是: colorsys 期望输入什么? 如何将输出转换为标准 HSV? (色相= 0-360,饱和度= 0-100,明度= 0-100)
最佳答案
Coordinates in all of these color spaces are floating point values. In the YIQ space, the Y coordinate is between 0 and 1, but the I and Q coordinates can be positive or negative. In all other spaces, the coordinates are all between 0 and 1.
https://docs.python.org/3/library/colorsys.html
您必须从 0 - 255 缩放到 0 - 1,或者将 RGB 值除以 255。如果使用 python 2,请确保不要进行楼层除法。
关于python - 使用 colorsys 将 RGB 转为 HSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37656768/