rename methods
This commit is contained in:
parent
7df9e27007
commit
5c1caffc64
|
@ -13,15 +13,16 @@ from multiprocessing import Pool
|
||||||
import PIL.ImageGrab
|
import PIL.ImageGrab
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import colorsys
|
import colorsys
|
||||||
|
from scipy.stats import mode
|
||||||
import win32gui, win32ui, win32con
|
import win32gui, win32ui, win32con
|
||||||
|
|
||||||
BOARDER_SIZE = 50
|
BOARDER_SIZE = 300
|
||||||
TOP_LEDS = 19
|
TOP_LEDS = 19
|
||||||
RIGHT_LEDS = 11
|
RIGHT_LEDS = 11
|
||||||
BUTTOM_LEDS = 19
|
BUTTOM_LEDS = 19
|
||||||
LEFT_LEDS = 11
|
LEFT_LEDS = 11
|
||||||
MIN_TIME = 0.05
|
MIN_TIME = 0.05
|
||||||
FAST_MODE = True
|
METHOD = 'MEDIAN' #MEAN/MEDIAN/MODE/CLUSTER_MEAN, WARNING: CLUSTER_MEAN might burn down your house.
|
||||||
SATURATION_BOOST_FACTOR = 2
|
SATURATION_BOOST_FACTOR = 2
|
||||||
NUM_CLUSTERS = 3
|
NUM_CLUSTERS = 3
|
||||||
KMEAN_QUALITY = 50
|
KMEAN_QUALITY = 50
|
||||||
|
@ -29,6 +30,15 @@ NUM_THREADS = 16
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
board = telemetrix_rpi_pico.TelemetrixRpiPico()
|
board = telemetrix_rpi_pico.TelemetrixRpiPico()
|
||||||
|
|
||||||
|
def sigint_handler(signal=None, frame=None):
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print ('KeyboardInterrupt is caught')
|
||||||
|
board.neopixel_clear()
|
||||||
|
sleep(0.75)
|
||||||
|
board.shutdown()
|
||||||
|
exit()
|
||||||
|
|
||||||
class size:
|
class size:
|
||||||
width = None
|
width = None
|
||||||
height = None
|
height = None
|
||||||
|
@ -36,26 +46,18 @@ class size:
|
||||||
def get_screenshot():
|
def get_screenshot():
|
||||||
return PIL.ImageGrab.grab()
|
return PIL.ImageGrab.grab()
|
||||||
|
|
||||||
def sigint_handler(signal=None, frame=None):
|
|
||||||
print ('KeyboardInterrupt is caught')
|
|
||||||
board.neopixel_clear()
|
|
||||||
sleep(0.75)
|
|
||||||
board.shutdown()
|
|
||||||
exit()
|
|
||||||
|
|
||||||
|
|
||||||
def find_dorminant_color(im):
|
def find_dorminant_color(im):
|
||||||
if FAST_MODE:
|
|
||||||
color = numpy.reshape(numpy.asarray(im),(-1,3))
|
color = numpy.reshape(numpy.asarray(im),(-1,3))
|
||||||
color = numpy.median(color,axis=0)
|
|
||||||
|
|
||||||
h,s,v = colorsys.rgb_to_hsv(r=color[0]/255,g=color[1]/255,b=color[2]/255)
|
|
||||||
s = min(1,s*SATURATION_BOOST_FACTOR)
|
|
||||||
r,g,b = colorsys.hsv_to_rgb(h=h,s=s,v=v)
|
|
||||||
return [r*255,g*255,b*255]
|
|
||||||
else:
|
|
||||||
|
|
||||||
|
|
||||||
|
if METHOD == 'MODE':
|
||||||
|
color = mode(color,axis=0).mode[0]
|
||||||
|
elif METHOD == 'MEDIAN':
|
||||||
|
color = np.median(color,axis=0)
|
||||||
|
elif METHOD == 'MEAN':
|
||||||
|
color = np.mean(color,axis=0)
|
||||||
|
elif METHOD == 'CLUSTER_MEAN':
|
||||||
im = im.resize((KMEAN_QUALITY, KMEAN_QUALITY))
|
im = im.resize((KMEAN_QUALITY, KMEAN_QUALITY))
|
||||||
ar = np.asarray(im)
|
ar = np.asarray(im)
|
||||||
shape = ar.shape
|
shape = ar.shape
|
||||||
|
@ -66,9 +68,9 @@ def find_dorminant_color(im):
|
||||||
counts, bins = np.histogram(vecs, len(codes))
|
counts, bins = np.histogram(vecs, len(codes))
|
||||||
|
|
||||||
index_max = np.argmax(counts)
|
index_max = np.argmax(counts)
|
||||||
peak = codes[index_max]
|
color = codes[index_max]
|
||||||
|
|
||||||
h,s,v = colorsys.rgb_to_hsv(r=peak[0]/255,g=peak[1]/255,b=peak[2]/255)
|
h,s,v = colorsys.rgb_to_hsv(r=color[0]/255,g=color[1]/255,b=color[2]/255)
|
||||||
s = min(1,s*SATURATION_BOOST_FACTOR)
|
s = min(1,s*SATURATION_BOOST_FACTOR)
|
||||||
r,g,b = colorsys.hsv_to_rgb(h=h,s=s,v=v)
|
r,g,b = colorsys.hsv_to_rgb(h=h,s=s,v=v)
|
||||||
return [r*255,g*255,b*255]
|
return [r*255,g*255,b*255]
|
||||||
|
@ -120,4 +122,5 @@ if __name__ == '__main__':
|
||||||
sleep(0.001)
|
sleep(0.001)
|
||||||
print("loop time : "+str(timestamp()-lastTime))
|
print("loop time : "+str(timestamp()-lastTime))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
print("Retrying")
|
print("Retrying")
|
||||||
|
|
12
test.py
12
test.py
|
@ -1,12 +1,8 @@
|
||||||
import cupy
|
import cupy
|
||||||
import colorsys
|
import colorsys
|
||||||
from matplotlib impl plot
|
from scipy.stats import mode
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
peak = [124.3,231.5, 64.4]
|
a = np.asarray([[134,452,532],[123,531,532],[111,553,742]])
|
||||||
h,s,v = colorsys.rgb_to_hsv(r=peak[0]/255,g=peak[1]/255,b=peak[2]/255)
|
print(mode(a).mode[0])
|
||||||
SATURATION_BOOST_FACTOR = 1.5
|
|
||||||
s = min(1,s*SATURATION_BOOST_FACTOR)
|
|
||||||
print([h,s,v])
|
|
||||||
r,g,b = colorsys.hsv_to_rgb(h=h,s=s,v=v)
|
|
||||||
print([r,g,b])
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue