-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
executable file
·59 lines (44 loc) · 1.83 KB
/
app.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
import time
import edgeiq
def main():
facial_detector = edgeiq.ObjectDetection(
"alwaysai/res10_300x300_ssd_iter_140000")
facial_detector.load(engine=edgeiq.Engine.DNN)
print("Engine: {}".format(facial_detector.engine))
print("Accelerator: {}\n".format(facial_detector.accelerator))
print("Model:\n{}\n".format(facial_detector.model_id))
fps = edgeiq.FPS()
try:
with edgeiq.WebcamVideoStream(cam=0) as webcam, \
edgeiq.Streamer() as streamer:
# Allow webcam to warm up
time.sleep(2.0)
fps.start()
# loop detection
while True:
frame = webcam.read()
# detect human faces
results = facial_detector.detect_objects(
frame, confidence_level=.5)
frame = edgeiq.markup_image(
frame, results.predictions, colors=facial_detector.colors)
# Generate text to display on streamer
text = ["Model: {}".format(facial_detector.model_id)]
text.append(
"Inference time: {:1.3f} s".format(results.duration))
text.append("Faces:")
for prediction in results.predictions:
text.append("{}: {:2.2f}%".format(
prediction.label, prediction.confidence * 100))
streamer.send_data(frame, text)
fps.update()
if streamer.check_exit():
break
finally:
# stop fps counter and display information
fps.stop()
print("[INFO] elapsed time: {:.2f}".format(fps.get_elapsed_seconds()))
print("[INFO] approx. FPS: {:.2f}".format(fps.compute_fps()))
print("Program Ending")
if __name__ == "__main__":
main()