-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
110 lines (100 loc) · 2.97 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import cv2
from datetime import datetime
from multiprocessing import Process
from multiprocessing import Manager
import sys
import threading
import time
'''
try:
from picamera.array import PiRGBArray
from picamera import PiCamera
camera = PiCamera()
except:
'''
camera = cv2.VideoCapture(0)
from face_recognition import face_recognition
from face_recognition import face_recognition_ml
from display_helper import display
from drivers import camera_driver
CAMERA_PORT = 0
DELAY = 1
FPS =30
FULLSCREEN = False
ML_FLAG = False
DISPLAY = True
PROCESS_FLAG = False
manager = Manager()
data = manager.dict()
#data ["camera"] = camera
data["first_run"] = True
data["display_flag"] = True
data["debug_database"] = False
data["debug_train"] = False
def camera_feed():
global data
camera_ = camera
running = True
while running:
start_time = datetime.now()
delay = 1/float(FPS)
data["frame"] = camera_driver.cam_read(camera)["frame"]
dt = (datetime.now()-start_time).total_seconds()
if dt < delay:
time.sleep(delay - dt)
def video_loop(ML_FLAG = False):
global data
running = True
while running:
start_time = datetime.now()
if ML_FLAG:
data = face_recognition_ml.run(data)
else:
data = face_recognition.run(data)
dt = (datetime.now()-start_time).total_seconds()
if dt < DELAY:
time.sleep(DELAY - dt)
if __name__ == '__main__':
if len(sys.argv) > 1:
for command in sys.argv[1:]:
if command == "no_display":
DISPLAY = False
elif command == "debug_train":
data["debug_train"] = True
DISPLAY = False
elif command == "debug_database":
data["debug_database"] = True
elif command == "fullscreen":
FULLSCREEN = True
elif command == "ml":
ML_FLAG = True
elif command == "pro":
PROCESS_FLAG = True
else:
print("ERROR: Invalid command")
print("List of valid commands = [ no_display, debug_database, debug_train, fullscreen, ml, pro]")
sys.exit(1)
try:
video_feed = threading.Thread(target = camera_feed)
video_feed.daemon = True
video_feed.start()
time.sleep(5)
if PROCESS_FLAG:
video_thread = Process(target = video_loop, args=[ML_FLAG])
else:
video_thread = threading.Thread(target = video_loop, args=[ML_FLAG])
video_thread.daemon = True
video_thread.start()
if DISPLAY:
display.run(data, FULLSCREEN)
else:
while video_feed.isAlive():
video_thread.join(10)
# while True:
# try:
# if data["frame"] == None:
# print data
# except:
# pass
except KeyboardInterrupt:
sys.exit()