-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjectTracker.py
More file actions
66 lines (48 loc) · 1.3 KB
/
objectTracker.py
File metadata and controls
66 lines (48 loc) · 1.3 KB
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
#!/usr/bin/python
import time
import sys, getopt
import jevois
import colourConv
def printUsage():
print 'objectTrackerColourTuning.py -c <color hexcode> -t <tolerance>'
sys.exit(2)
# Main code
def main(argv):
colourHex = 0
tolerance = 10
# check for arguments
if len(argv) != 4:
printUsage()
# parse the arguments
try:
opts, args = getopt.getopt(argv,"hc:t:",["colour=","tolerance="])
except getopt.GetoptError:
printUsage()
# interpret the arguments
for opt, arg in opts:
if opt == '-h':
printUsage()
elif opt in ("-c", "--colour"):
try:
colourHex = int(arg, 16)
except Exception, e:
print >> sys.stderr, "Expected a hex colour code"
print >> sys.stderr, "Exception: %s" % str(e)
sys.exit(1)
elif opt in ("-t", "--tolerance"):
try:
tolerance = int(arg)
except Exception, e:
print >> sys.stderr, "Expected an integer number value"
print >> sys.stderr, "Exception: %s" % str(e)
sys.exit(1)
# convert hex colour into HSV colour (array)
colourHsv = colourConv.hexColourToJevoisHsv(colourHex)
# instantiate the jevois object
machine = jevois.Jevois()
# set the object tracker colour value
machine.setObjectTrackerColourParams(colourHsv, tolerance)
# close the serial port
machine.close()
if __name__ == "__main__":
main(sys.argv[1:])