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