improve color detection performance

This commit is contained in:
Lucca Ketterer 2020-07-29 16:33:16 +02:00
parent 3d21483e3e
commit 273fd18def

View File

@ -65,8 +65,6 @@ def ambient_light_thread():
send(rgb_to_hex(int(r*brighness),int(g*brighness),int(b*brighness)))
time.sleep(0.01)
def ambient_light():
t = Thread(target=ambient_light_thread)
@ -79,15 +77,21 @@ def ambient_light():
img = pyscreenshot.grab(backend="mss", childprocess=False, bbox=(1920,0,4480,1440))
# find dominant color
'''
img = np.array(img)
pixels = np.float32(img.reshape(-1, 3))
img = cv2.UMat(img)
n_colors = 1
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
flags = cv2.KMEANS_RANDOM_CENTERS
_, labels, palette = cv2.kmeans(pixels, n_colors, None, criteria, 10, flags)
_, labels, palette = cv2.kmeans(img, n_colors, None, criteria, 10, flags)
_, counts = np.unique(labels, return_counts=True)
dominant = palette[np.argmax(counts)]
_r,_g,_b = int(dominant[0]), int(dominant[1]), int(dominant[2])
'''
img.thumbnail((1,1))
_r,_g,_b = img.getpixel((0, 0))
def rgb_to_hex(r,g,b):
return "%02x%02x%02x" % (r,g,b)