Implemented a calculation of mean value between adjacent times
This commit is contained in:
parent
34406690f8
commit
a506e18657
25
color.py
25
color.py
@ -4,7 +4,7 @@ import serial
|
|||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
|
||||||
def compute_value(line, minimum, maximum, inv):
|
def compute_value(line, minimum, maximum):
|
||||||
line = line.split(" ")
|
line = line.split(" ")
|
||||||
if len(line) < 3:
|
if len(line) < 3:
|
||||||
return False
|
return False
|
||||||
@ -16,19 +16,20 @@ def compute_value(line, minimum, maximum, inv):
|
|||||||
elif value[i] < 0:
|
elif value[i] < 0:
|
||||||
value[i] = 0
|
value[i] = 0
|
||||||
|
|
||||||
if inv is True:
|
return value[0]
|
||||||
return 255-value[0], 255-value[1], 255-value[2]
|
|
||||||
else:
|
|
||||||
return value[0], value[1], value[2]
|
|
||||||
|
|
||||||
|
|
||||||
ser = serial.Serial("/dev/ttyACM0", 115200)
|
ser = serial.Serial("/dev/ttyACM0", 115200)
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
|
# Keep old value to determine a mean value
|
||||||
|
value = [[0, 0, 0], [0, 0, 0]]
|
||||||
|
font = pygame.font.Font(None, 36)
|
||||||
|
|
||||||
size = width, height = 640, 480
|
size = width, height = 640, 480
|
||||||
screen = pygame.display.set_mode(size)
|
screen = pygame.display.set_mode(size)
|
||||||
pygame.display.set_caption("Touchless 3D tracking")
|
pygame.display.set_caption("Touchless 3D tracking")
|
||||||
screen.fill((0, 0, 0))
|
screen.fill((0, 0, 0))(value[0]+value[1])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ser.open()
|
ser.open()
|
||||||
@ -80,14 +81,18 @@ if ser.isOpen():
|
|||||||
# Read line from serial
|
# Read line from serial
|
||||||
line = float(ser.readline())
|
line = float(ser.readline())
|
||||||
# Compute the value for red
|
# Compute the value for red
|
||||||
value = compute_value(line, minimum, maximum, False)
|
value[1] = value[0]
|
||||||
value_text = compute_value(line, minimum, maximum, True)
|
value[0] = compute_value(line, minimum, maximum)
|
||||||
|
value_bg = [value[0][i] + value[1][i] for i in range(3)]
|
||||||
|
value_text = [255 - i for i in compute_value(line, minimum,
|
||||||
|
maximum)]
|
||||||
|
|
||||||
if value is not False:
|
if value is not False:
|
||||||
screen.fill(value)
|
screen.fill((value_bg[0], value_bg[1], value_bg[2]))
|
||||||
|
|
||||||
# Display info in window
|
# Display info in window
|
||||||
label = font.render("Running...", 1, value_text)
|
label = font.render("Running...", 1, (value_text[0],
|
||||||
|
value_text[1], value_text[2]))
|
||||||
label_pos = label.get_rect()
|
label_pos = label.get_rect()
|
||||||
label_pos.centerx = screen.get_rect().centerx
|
label_pos.centerx = screen.get_rect().centerx
|
||||||
label_pos.centery = 20
|
label_pos.centery = 20
|
||||||
|
Loading…
Reference in New Issue
Block a user