Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
hackEns
TouchlessTracking
Commits
1c15c86c
Commit
1c15c86c
authored
Oct 05, 2013
by
Phyks
Browse files
Bug fixes
parent
8b55b5ea
Changes
2
Show whitespace changes
Inline
Side-by-side
color.py
View file @
1c15c86c
...
...
@@ -5,18 +5,22 @@ import pygame
def
compute_value
(
line
,
minimum
,
maximum
):
line
=
line
.
split
(
" "
)
if
len
(
line
)
<
3
:
return
False
value
=
[
0
,
0
,
0
]
for
i
in
range
(
3
):
if
maximum
[
i
]
-
minimum
[
i
]
!=
0
:
value
[
i
]
=
int
(
255
*
(
line
[
i
]
-
minimum
[
i
])
/
(
maximum
[
i
]
-
minimum
[
i
]))
else
:
value
[
i
]
=
0
if
value
[
i
]
>
255
:
value
[
i
]
=
255
elif
value
[
i
]
<
0
:
value
[
i
]
=
0
return
value
[
0
]
return
value
ser
=
serial
.
Serial
(
"/dev/ttyACM0"
,
115200
)
...
...
@@ -29,7 +33,7 @@ font = pygame.font.Font(None, 36)
size
=
width
,
height
=
640
,
480
screen
=
pygame
.
display
.
set_mode
(
size
)
pygame
.
display
.
set_caption
(
"Touchless 3D tracking"
)
screen
.
fill
((
0
,
0
,
0
))
(
value
[
0
]
+
value
[
1
])
screen
.
fill
((
0
,
0
,
0
))
try
:
ser
.
open
()
...
...
@@ -45,7 +49,7 @@ if ser.isOpen():
minimum
=
[
-
1
,
-
1
,
-
1
]
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."
)
# Display info in window
label
=
font
.
render
(
"Calibration..."
,
1
,
(
255
,
255
,
255
))
...
...
@@ -59,15 +63,22 @@ if ser.isOpen():
running
=
True
while
running
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
pygame
.
K
_RETUR
N
:
if
event
.
type
==
pygame
.
K
EYDOW
N
:
running
=
False
continue
line
=
ser
.
readline
()
line
=
line
.
decode
().
strip
(
"
\r\n
"
)
line
=
line
.
split
(
" "
)
line
=
[
int
(
j
or
0
)
for
j
in
line
]
line
=
float
(
ser
.
readline
())
for
i
in
range
(
3
):
if
line
[
i
]
<
minimum
[
i
]
or
minimum
[
i
]
<
0
:
minimum
[
i
]
=
line
[
i
]
if
line
[
i
]
>
maximum
[
i
]:
maximum
[
i
]
=
line
[
i
]
if
line
<
minimum
or
minimum
<
0
:
minimumR
=
line
if
line
>
maximum
:
maximumR
=
line
print
(
line
)
print
(
"Running..."
)
running
=
True
...
...
@@ -77,13 +88,18 @@ if ser.isOpen():
if
event
.
type
==
pygame
.
QUIT
or
event
.
type
==
pygame
.
KEYDOWN
:
pygame
.
quit
()
running
=
False
continue
# 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
value
[
1
]
=
value
[
0
]
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
,
maximum
)]
...
...
touchless_tracking/touchless_tracking.ino
View file @
1c15c86c
...
...
@@ -89,12 +89,12 @@ void setup() {
void
loop
()
{
// 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
(
time
(
PIN_G
,
MASK_G
)
,
DEC
);
//
Serial.print(time(PIN_G, MASK_G));
Serial
.
print
(
" "
);
Serial
.
print
(
time
(
PIN_B
,
MASK_B
)
,
DEC
);
Serial
.
print
(
"
\n
"
);
//
Serial.print(time(PIN_B, MASK_B));
Serial
.
print
ln
(
"
"
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment