Skip to content

Commit 7b4acc2

Browse files
committed
Update documentation and apply PEP8
1 parent 20227c4 commit 7b4acc2

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

README.md

+15-11
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@ The output may vary depending on your installed version, but it should look simi
5454
```
5555
usage: deface [--output O] [--thresh T] [--scale WxH] [--preview] [--boxes]
5656
[--draw-scores] [--mask-scale M]
57-
[--replacewith {blur,solid,none}]
57+
[--replacewith {blur,solid,none,img}] [--replaceimg REPLACEIMG]
5858
[--ffmpeg-config FFMPEG_CONFIG] [--backend {auto,onnxrt,opencv}]
5959
[--version] [--help]
60-
[input [input ...]]
60+
[input ...]
6161
6262
Video anonymization by face detection
6363
6464
positional arguments:
6565
input File path(s) or camera device name. It is possible to
6666
pass multiple paths by separating them by spaces or by
67-
using shell expansion (e.g. `$ deface vids/*.mp4`).
68-
Additionally you can pass a directory as an input in
69-
which case all files in the directory will be used as
70-
input. If a camera is installed, a live webcam demo can
71-
be started by running `$ deface cam` (which is a
72-
shortcut for `$ deface -p '<video0>'`).
67+
using shell expansion (e.g. `$ deface vids/*.mp4`).
68+
Alternatively, you can pass a directory as an input,
69+
in which case all files in the directory will be used
70+
as inputs. If a camera is installed, a live webcam
71+
demo can be started by running `$ deface cam` (which
72+
is a shortcut for `$ deface -p '<video0>'`.
7373
7474
optional arguments:
7575
--output O, -o O Output file name. Defaults to input path + postfix
@@ -83,11 +83,15 @@ optional arguments:
8383
--draw-scores Draw detection scores onto outputs.
8484
--mask-scale M Scale factor for face masks, to make sure that masks
8585
cover the complete face. Default: 1.3.
86-
--replacewith {blur,solid,none}
86+
--replacewith {blur,solid,none,img}
8787
Anonymization filter mode for face regions. "blur"
8888
applies a strong gaussian blurring, "solid" draws a
89-
solid black box and "none" does leaves the input
90-
unchanged. Default: "blur".
89+
solid black box, "none" does leaves the input
90+
unchanged and "img" replaces the face with a custom
91+
image. Default: "blur".
92+
--replaceimg REPLACEIMG
93+
Anonymization image for face regions. Requires
94+
--replacewith img option.
9195
--ffmpeg-config FFMPEG_CONFIG
9296
FFMPEG config arguments for encoding output videos.
9397
This argument is expected in JSON notation. For a list

deface/deface.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ def draw_det(
5656
frame[y1:y2, x1:x2] = roibox
5757
else:
5858
frame[y1:y2, x1:x2] = blurred_box
59-
elif replacewith == "img":
60-
target_size = (x2-x1, y2-y1)
59+
elif replacewith == 'img':
60+
target_size = (x2 - x1, y2 - y1)
6161
resized_replaceimg = cv2.resize(replaceimg, target_size)
62-
if replaceimg.shape[2] == 3:
62+
if replaceimg.shape[2] == 3: # RGB
6363
frame[y1:y2, x1:x2] = resized_replaceimg
64-
elif replaceimg.shape[2] == 4:
64+
elif replaceimg.shape[2] == 4: # RGBA
6565
frame[y1:y2, x1:x2] = frame[y1:y2, x1:x2] * (1 - resized_replaceimg[:, :, 3:] / 255) + resized_replaceimg[:, :, :3] * (resized_replaceimg[:, :, 3:] / 255)
6666
elif replacewith == 'none':
6767
pass
@@ -241,7 +241,7 @@ def parse_cli_args():
241241
parser = argparse.ArgumentParser(description='Video anonymization by face detection', add_help=False)
242242
parser.add_argument(
243243
'input', nargs='*',
244-
help=f'File path(s) or camera device name. It is possible to pass multiple paths by separating them by spaces or by using shell expansion (e.g. `$ deface vids/*.mp4`). If a camera is installed, a live webcam demo can be started by running `$ deface cam` (which is a shortcut for `$ deface -p \'<video0>\'`.')
244+
help=f'File path(s) or camera device name. It is possible to pass multiple paths by separating them by spaces or by using shell expansion (e.g. `$ deface vids/*.mp4`). Alternatively, you can pass a directory as an input, in which case all files in the directory will be used as inputs. If a camera is installed, a live webcam demo can be started by running `$ deface cam` (which is a shortcut for `$ deface -p \'<video0>\'`.')
245245
parser.add_argument(
246246
'--output', '-o', default=None, metavar='O',
247247
help='Output file name. Defaults to input path + postfix "_anonymized".')
@@ -265,10 +265,10 @@ def parse_cli_args():
265265
help='Scale factor for face masks, to make sure that masks cover the complete face. Default: 1.3.')
266266
parser.add_argument(
267267
'--replacewith', default='blur', choices=['blur', 'solid', 'none', 'img'],
268-
help='Anonymization filter mode for face regions. "blur" applies a strong gaussian blurring, "solid" draws a solid black box, "none" does leaves the input unchanged and "img" replace the face with a custom image. Default: "blur".')
268+
help='Anonymization filter mode for face regions. "blur" applies a strong gaussian blurring, "solid" draws a solid black box, "none" does leaves the input unchanged and "img" replaces the face with a custom image. Default: "blur".')
269269
parser.add_argument(
270270
'--replaceimg', default='replace_img.png',
271-
help='Anonymization img for face regions. Requires --replacewith img option.')
271+
help='Anonymization image for face regions. Requires --replacewith img option.')
272272
parser.add_argument(
273273
'--ffmpeg-config', default={"codec": "libx264"}, type=json.loads,
274274
help='FFMPEG config arguments for encoding output videos. This argument is expected in JSON notation. For a list of possible options, refer to the ffmpeg-imageio docs. Default: \'{"codec": "libx264"}\'.'

0 commit comments

Comments
 (0)