Files
obfuscation_platform/project/obfuscation/pixelation.py
T

23 lines
653 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import cv2
import numpy as np
from obfuscation.base_obfuscation_technique import ObfuscationTechnique
class Pixelation(ObfuscationTechnique):
"""
Down‑scale the ROI to a user‑defined *number* of blocks, then up‑scale again.
Parameters
"""
def __init__(self):
self.blocks = 8
def obfuscate(self, face_roi_img_bgr: np.ndarray) -> np.ndarray:
h, w = face_roi_img_bgr.shape[:2]
tmp = cv2.resize(face_roi_img_bgr, (self.blocks, self.blocks), interpolation=cv2.INTER_LINEAR)
return cv2.resize(tmp, (w, h), interpolation=cv2.INTER_NEAREST)
def name(self) -> str:
return "Pixel"