import cv2 class DetectorMovimiento: def __init__(self, umbral_pixeles=5000): self.bg = cv2.createBackgroundSubtractorMOG2(history=500, varThreshold=50) self.umbral = umbral_pixeles def hay_movimiento(self, frame) -> bool: mask = self.bg.apply(frame) return cv2.countNonZero(mask) > self.umbral