How to convert RGB value to XY value for Phillips Hue Bulb

How to correctly convert rgb pixel values ​​to an image that I took for the XY values ​​needed to send to a Phillips Hue device? My current code does the following: 1: Take a picture, find the most common colors. 2: Loop toss them and then take another shot. 3: Send this value to the Phillips Hue balls. If you need more code, tell me, I can share everything if that helps. I am particularly confused here, as converting to colormath gives me xyz, not just xy. And if I give the conversion rbg (0,0,0), it gives the color in the color scheme.

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."
+2
source share
1 answer

Z XYZ, colormath, Z, , , , X Y . , Z X Y, .

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

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

: CIE 1931 .

+3

Source: https://habr.com/ru/post/1535246/


All Articles