From dfa1e14015c7da96db6777e894f3cfc2f938f983 Mon Sep 17 00:00:00 2001 From: Daniel Ecer Date: Wed, 17 Mar 2021 23:45:45 +0000 Subject: [PATCH 1/2] added invert filter --- README.md | 1 + ...deo-bodypix-replace-background-template.yml | 4 ++++ layered_vision/filters/invert.py | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 layered_vision/filters/invert.py diff --git a/README.md b/README.md index cf5d582..bc9aa43 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ The following filters are currently supported: | `bilateral` | Applies a [bilateral filter](https://en.wikipedia.org/wiki/Bilateral_filter), using `d`, `sigma_color` and `sigma_space` parameters. | | `motion_blur` | Adds a motion blur to the image or channel. That could be used to make an alpha mask move more slowly | | `pixelate` | Pixelates the input. | +| `invert` | Inverts the input. e.g. `black` to `white` | Every *filter* may have additional properties. Please refer to the [examples](https://github.com/de-code/layered-vision/tree/develop/example-config) (or come back in the future) for more detailed information. diff --git a/example-config/display-video-bodypix-replace-background-template.yml b/example-config/display-video-bodypix-replace-background-template.yml index 9db708d..6a6b2a0 100644 --- a/example-config/display-video-bodypix-replace-background-template.yml +++ b/example-config/display-video-bodypix-replace-background-template.yml @@ -26,6 +26,10 @@ layers: internal_resolution: 0.5 threshold: 0.5 cache_model_result_secs: 0 + - id: invert + filter: invert + channel: alpha + enabled: false - id: erode filter: erode channel: alpha diff --git a/layered_vision/filters/invert.py b/layered_vision/filters/invert.py new file mode 100644 index 0000000..bfd31fc --- /dev/null +++ b/layered_vision/filters/invert.py @@ -0,0 +1,18 @@ +import logging + +import cv2 + +from layered_vision.utils.image import ImageArray +from layered_vision.filters.api import AbstractOptionalChannelFilter + + +LOGGER = logging.getLogger(__name__) + + +class InvertFilter(AbstractOptionalChannelFilter): + def do_channel_filter(self, image_array: ImageArray) -> ImageArray: + LOGGER.debug('invert, image_array dtype: %s', image_array.dtype) + return cv2.bitwise_not(image_array) + + +FILTER_CLASS = InvertFilter From ef0128edf1f71119b29f5795924c019d91d05c96 Mon Sep 17 00:00:00 2001 From: Daniel Ecer Date: Wed, 17 Mar 2021 23:48:25 +0000 Subject: [PATCH 2/2] added pixelate to template config --- .../display-video-bodypix-replace-background-template.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/example-config/display-video-bodypix-replace-background-template.yml b/example-config/display-video-bodypix-replace-background-template.yml index 6a6b2a0..c3de272 100644 --- a/example-config/display-video-bodypix-replace-background-template.yml +++ b/example-config/display-video-bodypix-replace-background-template.yml @@ -55,6 +55,10 @@ layers: channel: alpha frame_count: 3 decay: 0 + - id: pixelate + filter: pixelate + value: 0.1 + enabled: false - id: fg enabled: false no_source: false