import cv2 import numpy capture = cv2.VideoCapture(0) i=0 last_frame = None while True: ret, new_frame = capture.read() if ret: cv2.imwrite('frame_%d.jpg' % i, new_frame) if not last_frame: diff = new_frame - last_frame percent_motion = numpy.count_nonzero(diff) / float(new_frame.size) print 'percent motion seems to be %.2f' % (percent_motion) last_frame = i += 1 else: print 'seems like we\'re at the end of the file' break