-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRunProcess.py
More file actions
71 lines (56 loc) · 2.52 KB
/
Copy pathRunProcess.py
File metadata and controls
71 lines (56 loc) · 2.52 KB
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
import argparse
import logging.config
import os
import warnings
import ReadVideo
warnings.filterwarnings('ignore')
logging.config.fileConfig('logging.ini', disable_existing_loggers=False)
log = logging.getLogger(__name__)
PATH_TO_VIDEO = 'video/'
def create_parser():
parser = argparse.ArgumentParser(description='tutorial:')
parser.add_argument('--video', '-v', dest='video', default='test.mp4', help='Videofile or stream url')
parser.add_argument('--file', '-f', dest='filename', default='no', help='File with coordinates of plates')
parser.add_argument('--type', '-t', dest='type', default='v', help='s-stream, v-videofile')
parser.add_argument('--gpu', '-g', dest='gpu', default=False, help='If you use gpu write --gpu=True')
parser.add_argument('--sec', '-s', dest='sec', default=0.5, help='Sec between process the cadrs')
parser.add_argument('--frame', '-fr', dest='frame', default=False, help='Size of frame')
return parser
def parse_args(args):
if args.gpu:
os.environ['CUDA_VISIBLE_DEVICES'] = '0' # For GPU inference
os.environ["TF_FORCE_GPU_ALLOW_GROWTH"] = "true" # For GPU inference
# dynamically grow the memory used on the GPU
from tensorflow.compat.v1.keras.backend import set_session
import tensorflow as tf
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.compat.v1.Session(config=config)
set_session(sess)
else:
os.environ['CUDA_VISIBLE_DEVICES'] = '' # For CPU inference
if args.type == 'v':
name_of_video = os.path.splitext(args.video)[0] # name of video without file extension
path_video = PATH_TO_VIDEO + args.video
if not os.path.exists(path_video):
log.error(" %s didn't find" % path_video)
exit(1)
else:
name_of_video = 'online_camera'
path_video = args.video
if args.filename == 'no': # if name of file with txt doesn't point - it will be name of video
filename = name_of_video + '.txt'
else:
filename = args.filename
if args.sec == '0':
sec = 0.1
else:
sec = float(args.sec)
return path_video, filename, name_of_video, sec
if __name__ == '__main__':
parser = create_parser()
args = parser.parse_args()
path_video, filename, name_of_video, sec = parse_args(args)
log.info(' Run video %s' % args.video)
ReadVideo.read_video(path_video, filename, args.type, name_of_video, sec, args.frame)
log.info(' Close video %s \n\n' % args.video)