Bug fixes
This commit is contained in:
parent
8b55b5eab5
commit
1c15c86c6d
40
color.py
40
color.py
@ -5,18 +5,22 @@ import pygame
|
|||||||
|
|
||||||
|
|
||||||
def compute_value(line, minimum, maximum):
|
def compute_value(line, minimum, maximum):
|
||||||
line = line.split(" ")
|
|
||||||
if len(line) < 3:
|
if len(line) < 3:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
value = [0, 0, 0]
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
|
if maximum[i]-minimum[i] != 0:
|
||||||
value[i] = int(255*(line[i]-minimum[i])/(maximum[i]-minimum[i]))
|
value[i] = int(255*(line[i]-minimum[i])/(maximum[i]-minimum[i]))
|
||||||
|
else:
|
||||||
|
value[i] = 0
|
||||||
|
|
||||||
if value[i] > 255:
|
if value[i] > 255:
|
||||||
value[i] = 255
|
value[i] = 255
|
||||||
elif value[i] < 0:
|
elif value[i] < 0:
|
||||||
value[i] = 0
|
value[i] = 0
|
||||||
|
|
||||||
return value[0]
|
return value
|
||||||
|
|
||||||
|
|
||||||
ser = serial.Serial("/dev/ttyACM0", 115200)
|
ser = serial.Serial("/dev/ttyACM0", 115200)
|
||||||
@ -29,7 +33,7 @@ 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))(value[0]+value[1])
|
screen.fill((0, 0, 0))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ser.open()
|
ser.open()
|
||||||
@ -45,7 +49,7 @@ if ser.isOpen():
|
|||||||
minimum = [-1, -1, -1]
|
minimum = [-1, -1, -1]
|
||||||
|
|
||||||
print("Calibration :")
|
print("Calibration :")
|
||||||
print("Press any key to launch the program when calibration is" +
|
print("Press any key to launch the program when calibration is " +
|
||||||
"finished.")
|
"finished.")
|
||||||
# Display info in window
|
# Display info in window
|
||||||
label = font.render("Calibration...", 1, (255, 255, 255))
|
label = font.render("Calibration...", 1, (255, 255, 255))
|
||||||
@ -59,15 +63,22 @@ if ser.isOpen():
|
|||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.K_RETURN:
|
if event.type == pygame.KEYDOWN:
|
||||||
running = False
|
running = False
|
||||||
|
continue
|
||||||
|
|
||||||
line = float(ser.readline())
|
line = ser.readline()
|
||||||
|
line = line.decode().strip("\r\n")
|
||||||
|
line = line.split(" ")
|
||||||
|
line = [int(j or 0) for j in line]
|
||||||
|
|
||||||
if line < minimum or minimum < 0:
|
for i in range(3):
|
||||||
minimumR = line
|
if line[i] < minimum[i] or minimum[i] < 0:
|
||||||
if line > maximum:
|
minimum[i] = line[i]
|
||||||
maximumR = line
|
if line[i] > maximum[i]:
|
||||||
|
maximum[i] = line[i]
|
||||||
|
|
||||||
|
print(line)
|
||||||
|
|
||||||
print("Running...")
|
print("Running...")
|
||||||
running = True
|
running = True
|
||||||
@ -77,13 +88,18 @@ if ser.isOpen():
|
|||||||
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
|
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN:
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
running = False
|
running = False
|
||||||
|
continue
|
||||||
|
|
||||||
# Read line from serial
|
# Read line from serial
|
||||||
line = float(ser.readline())
|
line = ser.readline()
|
||||||
|
line = line.decode().strip("\r\n")
|
||||||
|
line = line.split(" ")
|
||||||
|
line = [int(j or 0) for j in line]
|
||||||
|
|
||||||
# Compute the value for red
|
# Compute the value for red
|
||||||
value[1] = value[0]
|
value[1] = value[0]
|
||||||
value[0] = compute_value(line, minimum, maximum)
|
value[0] = compute_value(line, minimum, maximum)
|
||||||
value_bg = [value[0][i] + value[1][i] for i in range(3)]
|
value_bg = [(value[0][i] + value[1][i])/2 for i in range(3)]
|
||||||
value_text = [255 - i for i in compute_value(line, minimum,
|
value_text = [255 - i for i in compute_value(line, minimum,
|
||||||
maximum)]
|
maximum)]
|
||||||
|
|
||||||
|
@ -89,12 +89,12 @@ void setup() {
|
|||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Print output to serial in decimal
|
// Print output to serial in decimal
|
||||||
Serial.print(time(PIN_R, MASK_R), DEC);
|
Serial.print(time(PIN_R, MASK_R));
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
|
|
||||||
Serial.print(time(PIN_G, MASK_G), DEC);
|
//Serial.print(time(PIN_G, MASK_G));
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
|
|
||||||
Serial.print(time(PIN_B, MASK_B), DEC);
|
//Serial.print(time(PIN_B, MASK_B));
|
||||||
Serial.print("\n");
|
Serial.println(" ");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user