-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpysolo_eval_background.py
executable file
·62 lines (51 loc) · 2.57 KB
/
pysolo_eval_background.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
#!/usr/bin/env python
import cv2
import logging.config
import sys
from argparse import ArgumentParser
from pysolo_config import load_config
from pysolo_video import (estimate_background, MovieFile)
def main():
parser = ArgumentParser(usage='prog [options]')
parser.add_argument('-c', '--config',
dest='config_file', required=True,
metavar='CONFIG_FILE', help='The full path to the config file to open')
parser.add_argument('-l', '--log-config',
default='logger.conf', dest='log_config_file',
metavar='LOG_CONFIG_FILE', help='The full path to the log config file to open')
parser.add_argument('--background-image-file',
default='background.jpg', dest='background_image_file',
help='The full path of the saved background image')
parser.add_argument('--start-frame-time', default=-1, type=int, dest='start_frame_pos',
help='Start frame time in seconds')
parser.add_argument('--end-frame-time', default=-1, type=int, dest='end_frame_pos',
help='End frame time in seconds')
parser.add_argument('--smooth-filter-size', default=3, type=int, dest='gaussian_filter_size',
help='End frame time in seconds')
args = parser.parse_args()
# setup logger
logging.config.fileConfig(args.log_config_file)
_logger = logging.getLogger('tracker')
if args.config_file is None:
_logger.warning('Missing config file')
parser.exit(1, 'Missing config file\n')
# load config file
config, errors = load_config(args.config_file)
errors |= set(config.validate_source())
if len(errors) == 0:
image_source = MovieFile(config.get_source(),
start_msecs=args.start_frame_pos * 1000,
end_msecs=args.end_frame_pos * 1000,
resolution=config.get_image_size())
if (image_source.is_opened()):
background_image = estimate_background(image_source,
gaussian_filter_size=(args.gaussian_filter_size, args.gaussian_filter_size),
gaussian_sigma=0)
cv2.imwrite(args.background_image_file, background_image)
image_source.close()
else:
_logger.error('Error opening %s' % config.get_source())
else:
_logger.error('Config load error: %r' % errors)
if __name__ == '__main__':
sys.exit(main())