-
Notifications
You must be signed in to change notification settings - Fork 7
/
reference_points_picker.py
84 lines (70 loc) · 2.39 KB
/
reference_points_picker.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import argparse
import logging
from pathlib import Path
import OTVision.config as config
from OTVision.helpers.log import DEFAULT_LOG_FILE, LOGGER_NAME, VALID_LOG_LEVELS, log
from OTVision.transform.reference_points_picker import ReferencePointsPicker
def parse() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Reference Points Picker")
parser.add_argument(
"-f",
"--file",
type=str,
help="Path to the video or image in which reference points are to be clicked",
)
parser.add_argument(
"--log_level_console",
type=str,
choices=VALID_LOG_LEVELS,
help="Log level for logging to the console",
required=False,
)
parser.add_argument(
"--log_level_file",
type=str,
choices=VALID_LOG_LEVELS,
help="Log level for logging to a log file",
required=False,
)
parser.add_argument(
"--logfile",
default=str(DEFAULT_LOG_FILE),
type=str,
help="Specify log file directory.",
required=False,
)
parser.add_argument(
"--logfile_overwrite",
action="store_true",
help="Overwrite log file if it already exists.",
required=False,
)
return parser.parse_args()
def _configure_logger(args: argparse.Namespace) -> logging.Logger:
# Add console handler to existing logger instance
if args.log_level_console is None:
log_level_console = config.CONFIG[config.LOG][config.LOG_LEVEL_CONSOLE]
else:
log_level_console = args.log_level_console
log.add_console_handler(level=log_level_console)
# Add file handler to existing logger instance
if args.log_level_file is None:
log_level_file = config.CONFIG[config.LOG][config.LOG_LEVEL_FILE]
else:
log_level_file = args.log_level_file
log.add_console_handler(level=log_level_console)
log.add_file_handler(
Path(args.logfile).expanduser(),
log_level_file,
args.logfile_overwrite,
)
# Return and overwrite log variable pointing to same global object from log.py
return logging.getLogger(LOGGER_NAME)
def main() -> None:
args = parse()
log = _configure_logger(args)
log.info("Call reference points picker from command line")
log.info(f"Arguments: {vars(args)}")
ReferencePointsPicker(file=Path(args.file))
if __name__ == "__main__":
main()