【问题标题】:How do I convert an RGB value to a XY value for the Phillips Hue Bulb如何将 RGB 值转换为 Phillips Hue Bulb 的 XY 值
【发布时间】:2013-12-31 09:14:28
【问题描述】:

如何正确地将我拍摄的图片中的像素 rgb 值转换为发送到 Phillips Hue 设备所需的 XY 值? 我当前的代码执行以下操作: 1:拍照,找出最常见的颜色。 2:循环扔它们,然后再拍一张照片。 3:将值发送到 Phillips Hue Bulbs。 如果您需要更多代码,请告诉我,如果有帮助,我可以分享所有内容。 我在这里特别困惑,因为颜色数学的转换给了我一个 xyz 而不仅仅是一个 xy。如果我给出 rbg(0,0,0) 的转换,它会在色调灯泡上给出一段时间的颜色。

from beautifulhue.api import Bridge
from colormath.color_objects import RGBColor
from time import sleep

    while True:
    from pprint import pprint
    color_set = colors_from_cam()
    pprint(color_set)

    for item in color_set:
        print "Getting the color"
        pprint(item)
        time_length = item[0] # prominence
        red, green, blue = item[1] # colors
        #Set a lights attributes based on RGB colors.
        rgb_color = RGBColor(red,green,blue)
        xyz_color = rgb_color.convert_to('xyz', target_rgb='cie_rgb')
        xyz_x = xyz_color.xyz_x
        xyz_y = xyz_color.xyz_y
        xyz_z = xyz_color.xyz_z
        resource = {
            'which':3,
            'data':{
            'state':{'on':True,
                     'xy':[xyz_x, xyz_y],
                         'transitiontime': 1,
                     'bri': 255}
            }
        }
        bridge.light.update(resource)
        print "sleeping"
        sleep(1)
    sleep(2)
    print "taking another picture."

【问题讨论】:

    标签: python philips-hue


    【解决方案1】:

    Z 是您从 colormath 的转换中收到的 XYZ 值的必需组件,因此当您仅将 X 和 Y 发送到色调时,省略 Z 可能不是您想要做的。我相信您需要将 Z 集成到您的 X 和 Y 值中,以将它们标准化为 2D 颜色矩阵。

    x = X / (X + Y + Z);

    y = Y / (X + Y + Z);

    有关这些公式,请参阅:CIE 1931 color space,更具体地说,Chromaticity Diagram

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-06
      • 1970-01-01
      • 2016-12-17
      • 2019-05-09
      • 2012-10-29
      • 2011-01-24
      • 2013-05-10
      • 2018-11-06
      相关资源
      最近更新 更多