import numpy as np import os import time import cv2 cap = cv2.VideoCapture(0) # Gaussian Mixture-based Background/Foreground Segmentation fgbg = cv2.createBackgroundSubtractorMOG2(50,200,True) frameCount = 0 snapCount = 0 while(cap.isOpened()): ret, frame = cap.read() if frame is None: break frameCount += 1 resizedFrame = cv2.resize(frame,(0,0),fx=0.5,fy=0.5) fgmask = fgbg.apply(resizedFrame) count = np.count_nonzero(fgmask) # Waiting for focus if(frameCount > 30 and count > 1000 ): print('Motion detected') print('Frame: %d, Pixel Count: %d' % (frameCount, count) if(snapCount > 5): cv2.imwrite('snap.jpeg',frame) snapCount = 0 # Not included # os.system("sendemailc.exe") # else snapCount += 1 cv2.imshow('frame', resizedFrame) cv2.imshow('mask', fgmask) # Type Esc to quit if cv2.waitKey(33) >= 0: break cap.release() cv2.destroyAllWindows()