definitively going somewhere.
This commit is contained in:
1 parent
7179ff5fc1
commit
d7017c756b
7 files changed
+139
-41
No files matched your search
@@ -1,28 +1,69 @@
|
||||
import time
|
||||
from contextlib import closing
|
||||
from pathlib import Path
|
||||
|
||||
from dodgeballtracker.helper import time_tracker
|
||||
from dodgeballtracker.logic import (DetectedObjectBox,
|
||||
DodgeballTracker,
|
||||
get_court_perspective_transform)
|
||||
import numpy as np
|
||||
import logging
|
||||
import click
|
||||
from typing import ContextManager
|
||||
|
||||
from dodgeballtracker.video_writer import (MP4VVideoWriter, VideoWriter,
|
||||
MP4VVideoWriterWithFrame)
|
||||
|
||||
here = Path(__file__).parent
|
||||
input_dir = here / '..' / 'data'
|
||||
output_dir = here / '..' / 'outputs'
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@click.group()
|
||||
@click.option('--debug/--no-debug', default=False)
|
||||
def cli(debug):
|
||||
logging.basicConfig(filename='tracker.log', level=logging.DEBUG)
|
||||
|
||||
detected_box_objects = [
|
||||
DetectedObjectBox.from_viridis(threshold) for threshold in np.arange(0.5, 1, 0.05)
|
||||
]
|
||||
|
||||
input_video = input_dir / "small.mp4"
|
||||
output_video = output_dir / "foo.mp4"
|
||||
def get_output(input_: Path, proposed_output: Path | None) -> Path:
|
||||
if proposed_output is not None:
|
||||
return proposed_output
|
||||
return output_dir / input_.name
|
||||
|
||||
|
||||
def get_video_writer(display_frame: bool,
|
||||
video_input: Path,
|
||||
video_output: Path) -> ContextManager[VideoWriter]:
|
||||
if display_frame:
|
||||
return closing(
|
||||
MP4VVideoWriterWithFrame.from_frame(video_input, video_output))
|
||||
return closing(MP4VVideoWriter.from_frame(video_input, video_output))
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.option('--input', '-i', 'input_',
|
||||
type=click.Path(readable=True, path_type=Path))
|
||||
@click.option('--output', '-o', type=click.Path(path_type=Path))
|
||||
@click.option('--display-video', '-d', type=bool, is_flag=True, show_default=True, default=False)
|
||||
def process(input_: Path, output: Path | None, display_video: bool):
|
||||
output = get_output(input_, output)
|
||||
detected_box_objects = [
|
||||
DetectedObjectBox.from_viridis(threshold) for threshold in
|
||||
np.arange(0.5, 1, 0.05)
|
||||
]
|
||||
|
||||
transformation_matrix = get_court_perspective_transform()
|
||||
|
||||
dodgeball_tracker = DodgeballTracker(input_video, output_video, detected_box_objects, transformation_matrix)
|
||||
with get_video_writer(display_video, input_, output) as video_writer:
|
||||
tracker = DodgeballTracker(input_,
|
||||
output,
|
||||
video_writer,
|
||||
detected_box_objects,
|
||||
transformation_matrix)
|
||||
|
||||
dodgeball_tracker.main()
|
||||
with time_tracker():
|
||||
tracker.main()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
cli()
|
||||
Reference in new issue
Block a user