Skip to content

Commit

Permalink
Merge pull request tfaehse#9 from tfaehse/feature/cli
Browse files Browse the repository at this point in the history
Add rudimentary CLI for blurring videos
  • Loading branch information
tfaehse authored Apr 3, 2022
2 parents 3b06889 + f093188 commit 8eaf3cd
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
## Weights

Expand Down
67 changes: 67 additions & 0 deletions dashcamcleaner/cli.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 8eaf3cd

Please sign in to comment.