• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Philliphotoshop Hue Bulb的RGB值转换为XY值

用户头像
it1352
帮助1

问题说明

如何正确地将拍摄的图片中的像素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."

正确答案

#1

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色彩空间,尤其是查看全文

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfigih
系列文章
更多 icon
同类精品
更多 icon
继续加载