-
Notifications
You must be signed in to change notification settings - Fork 0
/
am62a_sign1.py
84 lines (59 loc) · 2.37 KB
/
am62a_sign1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# American Sign Language letter trainer for Texas Instruments AM62A
# Edge Impulse BYOM feature
# Roni Bandini @RoniBandini
# November 2023 MIT License
# https://bandini.medium.com
import subprocess
import time
import json
import random
from art import *
# Letters in trained model
myLetters= ["A","B","C","D","F","G","J","K","L","O"]
# choose one
selectedLetter=random.choice(myLetters)
# Edge Impulse runner sent to a file for parsing
output_file = open('output.txt', 'w')
# Detection limit
confidenceLimit=0.6
print("American Sign Language Letter Trainer")
print("Texas Instruments AM62A and Edge Impulse BYOM")
print("Roni Bandini, October 2023, Argentina, @RoniBandini")
print("")
print("Stop with CTRL-C")
print("")
print("Please be ready to make the sign for...")
asciiLetter=text2art(selectedLetter,font='block',chr_ignore=True)
print(asciiLetter)
# start timers
start = time.time()
# Launch Impulse Runner in a subprocess sending the output to a file
proc1 = subprocess.Popen(["edge-impulse-linux-runner", "--force-engine tidl", "-force-target", "runner-linux-aarch64-am62a"], stdout=output_file)
with open("output.txt", "r") as f:
lines_seen = set()
while True:
line = f.readline()
if not line:
time.sleep(1)
continue
if ("Want to see a feed" in line):
print("You can start now")
if (": '" in line):
if (selectedLetter in line) and line not in lines_seen:
# separate using...
parts = line.split(': ')
# get second part but last 3 chars
myConfidence = parts[1][1:-3]
myConfidence = myConfidence.replace("'", "")
myConfidence = float(myConfidence)
# mark as seen
lines_seen.add(line)
if myConfidence>confidenceLimit:
# calculate ending time
end = time.time()
print("Well done! I have detected "+selectedLetter+ " with "+str( int(myConfidence*100) )+"% confidence")
print("Elapsed time: "+str(int(end - start))+" seconds")
#proc1.kill()
exit()
else:
print(selectedLetter+ " confidence: " +str( int(myConfidence*100) )+"%")