-
Notifications
You must be signed in to change notification settings - Fork 12
/
template_matching.py
67 lines (59 loc) · 2.08 KB
/
template_matching.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
import os
import click
from winnow.pipeline.match_templates import match_templates
from winnow.pipeline.pipeline_context import PipelineContext
from winnow.utils.config import resolve_config
from winnow.utils.files import scan_videos, scan_videos_from_txt
from winnow.utils.logging import configure_logging_cli
@click.command()
@click.option("--config", "-cp", help="path to the project config file", default=os.environ.get("WINNOW_CONFIG"))
@click.option(
"--list-of-files",
"-lof",
help="path to txt with a list of files for processing - overrides source folder from the config file",
default=None,
)
@click.option(
"--frame-sampling",
"-fs",
help=(
"Sets the sampling strategy (values from 1 to 10 - eg "
"sample one frame every X seconds) - overrides frame "
"sampling from the config file"
),
default=None,
)
@click.option(
"--save-frames",
"-sf",
help="Whether to save the frames sampled from the videos - overrides save_frames on the config file",
default=None,
is_flag=True,
)
@click.option(
"--override", "-ovr", help="Overrides the previous template matches saved on the DB", default=None, is_flag=True
)
@click.option(
"--template-dir",
"-td",
help="path to a directory containing templates - overrides source folder from the config file",
default=None,
)
def main(config, list_of_files, frame_sampling, save_frames, override, template_dir):
logger = configure_logging_cli()
logger.info("Loading config file")
config = resolve_config(
config_path=config,
frame_sampling=frame_sampling,
save_frames=save_frames,
override_templates=override,
templates_dir=template_dir,
)
logger.info("Searching for Dataset Video Files")
if list_of_files is None:
videos = scan_videos(config.sources.root, "**", extensions=config.sources.extensions)
else:
videos = scan_videos_from_txt(list_of_files, extensions=config.sources.extensions)
match_templates(files=videos, pipeline=PipelineContext(config))
if __name__ == "__main__":
main()