-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
45 lines (38 loc) · 2.03 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
import argparse
import sys
from argparse import ArgumentParser
from lib import config
from lib.plots import display_analyze
from lib.opencovid import OpenCoVid
from distance.social_distance import SocialDistance
sys.path.insert(0, 'yolomask/')
from yolomask.mask_inference import YoloMask
from yolomask.person_inference import YoloPerson
if __name__ == '__main__':
parser: ArgumentParser = argparse.ArgumentParser()
parser.add_argument('--source', type=str, default='0', help='source') # file/folder, 0 for webcam
parser.add_argument('--dists', action='store_false', help='analyze social distancing')
parser.add_argument('--persons', action='store_false', help='analyze persons on frame')
parser.add_argument('--masks', action='store_false', help='analyze face mask wearing')
parser.add_argument('--show-inf', action='store_false', help='show inference on frame')
parser.add_argument('--mask-pt', nargs='+', type=str, default='yolomask/weights/yolomask.pt', help='model.pt path(s)')
parser.add_argument('--person-pt', nargs='+', type=str, default='yolomask/weights/yolov5s.pt', help='model.pt path(s)')
parser.add_argument('--rate', nargs='+', type=int, default=1, help='display rate speed in ms')
parser.add_argument('--project', default='OpenCoVid', help='main window and project name')
opt = parser.parse_args()
webcam = opt.source.isnumeric() or opt.source.endswith('.txt') or opt.source.lower().startswith(
('rtsp://', 'https://'))
config.initialize(opt.person_pt, opt.mask_pt, opt.project, opt.rate, [opt.source, 0][webcam], opt.show_inf)
# === OpenCoVid Lib Use =========================
init_filters = {}
# filters
if opt.persons:
init_filters["person"] = YoloPerson()
if opt.dists:
init_filters["dists"] = SocialDistance()
if opt.masks:
init_filters["masks"] = YoloMask()
ocv = OpenCoVid(callback=display_analyze, video_src=config.source,init_filters=init_filters)
# run
ocv.analyze()
# ===============================================