Spring-0's picture
Synced repo using 'sync_with_huggingface' Github Action
2012550 verified
raw
history blame contribute delete
578 Bytes
import cv2
from .base import CensoringMethod
class BlurCensor(CensoringMethod):
def __init__(self, blur_factor=99):
self.blur_factor = blur_factor
if self.blur_factor < 1 or self.blur_factor % 2 == 0:
raise ValueError("blur_factor must be a positive and odd number.")
def apply(self, frame, bbox):
x1, y1, x2, y2 = bbox[:4]
roi = frame[y1:y2, x1:x2]
blurred = cv2.GaussianBlur(roi, (self.blur_factor, self.blur_factor), 0)
frame[y1:y2, x1:x2] = blurred
return frame