Files
biblioteca_conocimiento_lab…/vigilancia/detector_movimiento.py

12 lines
338 B
Python

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