-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
99 lines (75 loc) · 2.01 KB
/
main.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
85
86
87
88
89
90
91
import argparse
import time
from Queue import Queue
from threading import Thread
import dlib
import cv2
import imutils
from Tracker import Tracker
from Detector import Detector
# cv2.imshow was not running on another thread-- learn why??
# Function for sending signals to arduino(this function will run on a thread)
stop_arduino_thread=False
def send_arduino(in_q):
global stop_arduino_thread
while(1):
if(stop_arduino_thread==True):
return
print "...."
data=in_q.get()
print "cX = ", data[0]
time.sleep(0.5)
def main():
ap = argparse.ArgumentParser()
ap.add_argument("-v", "--videopath", help="Path to video")
ap.add_argument("-d", "--detector", help="Detection Algo")
args = vars(ap.parse_args())
if(args["videopath"]=="0"):
source=0
elif(args["videopath"]=="1"):
source=1
else:
source=args["videopath"]
if(args["detector"]=="HG" or args["detector"]=="HC"):
detector_algo=args["detector"]
else:
print " Detector algo not correct"
quit()
############ Detection Part starts here ##############
dtector=Detector(src=source,detector=detector_algo).start()
while True:
frame=dtector.read()
frame=imutils.resize(frame, width=400)
cv2.imshow("Detection", frame)
key = cv2.waitKey(20) & 0xFF
if key == 27:
break
dtector.stop()
rect, img=dtector.get_roi()
cv2.destroyAllWindows()
# print rect
############ Detection Part ends here ##############
############ Tracking Part starts here ##############
global stop_arduino_thread
q=Queue()
tracker=Tracker(rect,img,src=source).start()
print tracker
data=tracker.get_points()
q.put(data)
thread_arduino = Thread(target=send_arduino, args=(q,))
thread_arduino.start()
while True:
frame=tracker.read()
frame=imutils.resize(frame, width=400)
cv2.imshow("Frame", frame)
data=tracker.get_points()
q.put(data)
key = cv2.waitKey(50) & 0xFF
if key==27:
break
stop_arduino_thread=True
tracker.stop()
cv2.destroyAllWindows()
############ Tracking ends starts here ##############
if __name__ == '__main__':
main()