From bae9baf5a5006ff442bca0ec5b342281d72726f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20F=C3=A4hse?= Date: Sun, 3 Apr 2022 16:09:19 +0200 Subject: [PATCH 1/2] Add rudimentary CLI for blurring videos --- dashcamcleaner/cli.py | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 dashcamcleaner/cli.py diff --git a/dashcamcleaner/cli.py b/dashcamcleaner/cli.py new file mode 100644 index 0000000..b0df41e --- /dev/null +++ b/dashcamcleaner/cli.py @@ -0,0 +1,67 @@ +import inspect +import os +import sys +from glob import glob +from argparse import ArgumentParser +from tqdm import tqdm + +from src.blurrer import VideoBlurrer + +class CLI(): + + def __init__(self, opt): + """ + Constructor + """ + self.opt = opt + self.blurrer = None + + def start_blurring(self): + # setup blurrer + self.blurrer = VideoBlurrer(self.opt.weights) + + # read inference size + inference_size = int(self.opt.inference_size) * 16 / 9 # ouch again + + # set up parameters + parameters = { + "input_path": self.opt.input, + "output_path": self.opt.output, + "blur_size": self.opt.blur_size, + "blur_memory": self.opt.frame_memory, + "threshold": self.opt.threshold, + "roi_multi": self.opt.roi_multi, + "inference_size": inference_size, + "quality": self.opt.quality + } + if self.blurrer: + self.blurrer.parameters = parameters + self.blurrer.start() + else: + print("No blurrer object!") + print("Blurrer started!") + self.blurrer.wait() + if self.blurrer and self.blurrer.result["success"]: + minutes = int(self.blurrer.result["elapsed_time"] // 60) + seconds = round(self.blurrer.result["elapsed_time"] % 60) + print(f"Video blurred successfully in {minutes} minutes and {seconds} seconds.") + else: + print("Blurring resulted in errors.") + +def parse_arguments(): + parser = ArgumentParser() + parser.add_argument("input", help="input video file path", type=str) + parser.add_argument("output", help="output video file path", type=str) + parser.add_argument("weights", help="weights file name", type=str) + parser.add_argument("inference_size", help="vertical inference size, e.g. 1080 or fHD", type=int) + parser.add_argument("threshold", help="detection threshold", type=float) + parser.add_argument("blur_size", help="granularitay of the blurring filter", type=int) + parser.add_argument("frame_memory", help="blur objects in the last x frames too", type=int) + parser.add_argument("roi_multi", help="increase/decrease area that will be blurred - 1 means no change", type=float) + parser.add_argument("quality", help="quality of the resulting video", type=int) + return parser.parse_args() + +if __name__ == "__main__": + opt = parse_arguments() + cli = CLI(opt) + cli.start_blurring() From f093188a3b91ff7abd5ad988d6ed817161a17b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20F=C3=A4hse?= Date: Sun, 3 Apr 2022 16:14:55 +0200 Subject: [PATCH 2/2] Update readme --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 6b3e7eb..f0a03f3 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,28 @@ Sometimes, a license plate might be missed for just one frame. This one frame, u For reference: even at 1080p inference, i.e. an inference scale of 1, a 1080p30fps video from my 70mai 1S processes at around 10 frames per second, a 1 minute clip takes ~3 minutes to blur on a 5820K/GTX1060 machine. +There's now also a fairly simple CLI to blur a video: + +``` +python dashcamcleaner/cli.py -h +usage: cli.py [-h] input output weights inference_size threshold blur_size frame_memory roi_multi quality + +positional arguments: + input input video file path + output output video file path + weights weights file name + inference_size vertical inference size, e.g. 1080 or fHD + threshold detection threshold + blur_size granularitay of the blurring filter + frame_memory blur objects in the last x frames too + roi_multi increase/decrease area that will be blurred - 1 means no change + quality quality of the resulting video + +optional arguments: + -h, --help show this help message and exit +``` +For now, there are no default values and all parameters have to be provided (in order). There's also no progress bar yet, but there should be an error/success message as soon as blurring is finished/has encountered any issues. + ## Weights