23 lines
653 B
Python
23 lines
653 B
Python
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" |