26 lines
808 B
Python
26 lines
808 B
Python
from obfuscation.base_obfuscation_technique import ObfuscationTechnique
|
||
import numpy as np
|
||
import cv2
|
||
|
||
class Blurring(ObfuscationTechnique):
|
||
"""
|
||
Gaussian‑blur a face ROI using a kernel that scales with its size.
|
||
"""
|
||
|
||
def __init__(self):
|
||
self.strength = 0.5 #50% of smaller dim (w/h)
|
||
|
||
@staticmethod
|
||
def _calc_kernel(h, w, strength,) -> int:
|
||
k = int(round(strength * min(h, w)))
|
||
k = k | 1 # make odd (bitwise OR 1)
|
||
k = max(3, k) # clamp
|
||
return k
|
||
|
||
def obfuscate(self, face_roi_img_bgr: np.ndarray) -> np.ndarray:
|
||
h, w = face_roi_img_bgr.shape[:2]
|
||
k = self._calc_kernel(h, w, self.strength)
|
||
return cv2.GaussianBlur(face_roi_img_bgr, ksize=(k, k), sigmaX=0, sigmaY=0)
|
||
|
||
def name(self) -> str:
|
||
return "Blur" |