From 180b41ffa45685df030953327edab4fe716dbb21 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 24 Apr 2025 11:33:28 +0200 Subject: [PATCH] feat: blacking out --- secure_pixelation/pixelation_process.py | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 secure_pixelation/pixelation_process.py diff --git a/secure_pixelation/pixelation_process.py b/secure_pixelation/pixelation_process.py new file mode 100644 index 0000000..65f7a06 --- /dev/null +++ b/secure_pixelation/pixelation_process.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +from pathlib import Path + +import cv2 +import numpy as np + +from .data_classes import RawImage + + +def blackout(raw_image: RawImage) -> np.ndarray: + image = raw_image.get_image() + + for box in raw_image.bounding_boxes: + cv2.rectangle(image, box, (0, 0, 0), -1) + + return image + + +def pixelate(to_detect: str, debug_drawings: bool = True): + raw_image = RawImage(to_detect) + + step_dir = raw_image.get_dir("steps") + def write_image(image: np.ndarray, name: str): + nonlocal debug_drawings + + f = str(step_dir / (name + raw_image.file.suffix)) + + if debug_drawings: + for box in raw_image.bounding_boxes: + cv2.rectangle(image, box, (0, 255, 255), 1) + + cv2.imwrite(f, image) + + step_1 = blackout(raw_image) + write_image(step_1, "step_1")