如何将Phillips Hue Bulb的RGB值转换为XY值 [英] How do I convert an RGB value to a XY value for the Phillips Hue Bulb

查看:236
本文介绍了如何将Phillips Hue Bulb的RGB值转换为XY值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何正确地将拍摄的图片中的像素rgb值转换为发送到Phillips Hue设备所需的XY值? 我当前的代码执行以下操作: 1:拍照,找到最普通的颜色. 2:循环扔掉它们,然后再拍一张照片. 3:将值发送到Phillips Hue Bulbs. 如果您需要更多代码,请告诉我,如果有帮助,我可以共享所有内容. 我在这里特别困惑,因为colormath的转换给了我xyz而不只是xy.而且,如果我使用rbg(0,0,0)进行通话,则它会在色相灯泡上显示一段时间的颜色.

How do I properly convert the pixel rgb values in a picture I have taken to th XY values needed to to send to the Phillips Hue device? My current code does the following: 1:Take a picture, find the most common colors. 2:Cycle throw them and then take another picture. 3:Send the value to a Phillips Hue Bulbs. If you need more of the code, do tell, I can share everything if it helps. I am particularly confused here as the conversion in colormath gives me an xyz and not just an xy. And if I give the converstion of rbg(0,0,0) it gives a while color on the hue bulb.

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."

推荐答案

Z是从colormath转换中收到的XYZ值的必需组成部分,因此,当仅发送X和Y时,省略Z可能不是您要执行的操作色调.我相信您需要将Z集成到X和Y值中,以将它们归一化为2D颜色矩阵.

Z is a required component of the XYZ values you received from colormath's conversion, so omitting Z is probably not what you meant to do when you sent only X and Y to hue. I believe you need to integrate Z into your X and Y values to normalize them to a 2D color matrix.

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

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

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

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

请参阅: CIE 1931色彩空间,尤其是

See: CIE 1931 color space and more specifically Chromaticity Diagram for these formulas.

这篇关于如何将Phillips Hue Bulb的RGB值转换为XY值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆