-
Notifications
You must be signed in to change notification settings - Fork 0
/
openvino_face_detection.py
executable file
·54 lines (49 loc) · 1.98 KB
/
openvino_face_detection.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
import json, os, shutil, sys, cv2
import argparse
from pathlib import Path
from time import perf_counter
from common import read_json
from common import config_logger
from model_api import Detection, draw_box
# def draw_box(info, palette):
# class_id = 0
# frame = info["frame"]
# output_transform = info['output_transform']
# if info["detections"] is not None and info["detections"] != []:
# if output_transform != None:
# frame = output_transform.resize(frame)
# boxes = info["detections"][0]
# for box in boxes:
# xmin, ymin, xmax, ymax = output_transform.scale([box[0], box[1], box[2], box[3]])
# cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), palette[class_id], 2)
# return frame
def main(args):
# Setting config
config = read_json(args.config)
# Source
from common.images_capture import open_images_capture
cap = open_images_capture(config['source'], config['loop'])
# Loading model
det = Detection(config)
palette = det.load_model()
while True:
frame = cap.read()
info = det.inference(frame)
# ---------------------------Drawing detecter to information-----------------------------------------------------------------------
if info is not None:
frame = draw_box(info, draw_key=True, palette=palette)
# ---------------------------Show--------------------------------------------------------------------------------------------------
cv2.imshow('Detection Results', frame)
key = cv2.waitKey(1)
ESC_KEY = 27
# Quit.
if key in {ord('q'), ord('Q'), ESC_KEY}:
break
cv2.destroyAllWindows()
sys.exit(0)
if __name__ == '__main__':
config_logger('./openvino_face_detection.log', 'w', "info")
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', help = "The path of application config")
args = parser.parse_args()
sys.exit(main(args) or 0)