improve color detection performance
This commit is contained in:
parent
3d21483e3e
commit
273fd18def
@ -64,14 +64,12 @@ def ambient_light_thread():
|
|||||||
print(r,g,b)
|
print(r,g,b)
|
||||||
send(rgb_to_hex(int(r*brighness),int(g*brighness),int(b*brighness)))
|
send(rgb_to_hex(int(r*brighness),int(g*brighness),int(b*brighness)))
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ambient_light():
|
def ambient_light():
|
||||||
|
|
||||||
t = Thread(target=ambient_light_thread)
|
t = Thread(target=ambient_light_thread)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
global _r,_g,_b
|
global _r,_g,_b
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@ -79,15 +77,21 @@ def ambient_light():
|
|||||||
img = pyscreenshot.grab(backend="mss", childprocess=False, bbox=(1920,0,4480,1440))
|
img = pyscreenshot.grab(backend="mss", childprocess=False, bbox=(1920,0,4480,1440))
|
||||||
|
|
||||||
# find dominant color
|
# find dominant color
|
||||||
|
'''
|
||||||
img = np.array(img)
|
img = np.array(img)
|
||||||
pixels = np.float32(img.reshape(-1, 3))
|
pixels = np.float32(img.reshape(-1, 3))
|
||||||
|
img = cv2.UMat(img)
|
||||||
n_colors = 1
|
n_colors = 1
|
||||||
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
|
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 200, .1)
|
||||||
flags = cv2.KMEANS_RANDOM_CENTERS
|
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)
|
_, counts = np.unique(labels, return_counts=True)
|
||||||
dominant = palette[np.argmax(counts)]
|
dominant = palette[np.argmax(counts)]
|
||||||
_r,_g,_b = int(dominant[0]), int(dominant[1]), int(dominant[2])
|
_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):
|
def rgb_to_hex(r,g,b):
|
||||||
return "%02x%02x%02x" % (r,g,b)
|
return "%02x%02x%02x" % (r,g,b)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user