spacepaste

  1.  
  2. import cv2
  3. import numpy
  4. capture = cv2.VideoCapture(0)
  5. i=0
  6. while True:
  7. ret, new_frame = capture.read()
  8. if ret:
  9. cv2.imwrite('frame_%d.jpg' % i, new_frame)
  10. diff = frame - last_frame
  11. percent_motion = numpy.count_nonzero(diff) / float(frame.size)
  12. print 'percent motion seems to be %.2f' % (percent_motion)
  13. i += 1
  14. else:
  15. print 'seems like we\'re at the end of the file'
  16. break
  17.