使用 colorsys 将 RGB 转为 HSV

RGB to HSV using colorsys

我正在尝试制作一个跟踪程序,该程序拍摄图像并显示具有指定颜色的对象所在的位置:

示例:https://imgur.com/a/8LR40

为了做到这一点,我现在正在使用 RGB,但使用它真的很难,所以我想将它转换成色调,这样更容易使用。我正在尝试使用 colorsys,但在做了一些研究之后,我不知道它想要什么参数以及它给出了什么。我曾尝试使用 colorizer.org 进行匹配,但我得到了一些废话。

>>> import colorsys
>>> colorsys.rgb_to_hsv(45,201,18)
(0.3087431693989071, 0.9104477611940298, 201)

alredy colorsys 没有按照记录运行,因为在 https://docs.python.org/2/library/colorsys.html 它说输出始终是 0 和 1 之间的浮点数,但值为 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,请确保不要进行底除法。