Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import cv
  2. import time
  3.  
  4. cv.NamedWindow("camera", 1)
  5.  
  6. capture = cv.CaptureFromCAM(0)
  7. cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH, 640)
  8. cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 480)
  9. cv.SetCaptureProperty(capture, cv.CV_CAP_PROP_FORMAT, cv.IPL_DEPTH_32F)
  10.  
  11. print "Starting. Space = save, Esc = quit"
  12. print "initializing timer"
  13. elapsedtime = time.clock()
  14. while True:
  15.     img = cv.QueryFrame(capture)
  16.     cv.ShowImage("camera", img)
  17.    
  18.     if ((time.clock() - elapsedtime) > 5):
  19.         t = time.localtime()
  20.         filename = "%s-%s-%s_%s-%s-%s" % (t.tm_mon, t.tm_mday, t.tm_year, t.tm_hour, t.tm_min, t.tm_sec)
  21.         cv.SaveImage("C:\\Users\\Chris\\Dropbox\\Security\\" + filename + ".jpg", img)
  22.         print ("saved " + filename + ".jpg")
  23.         print "resetting timer"
  24.         elapsedtime = time.clock()
  25.  
  26.     if cv.WaitKey(10) == 27:
  27.         print "exiting"
  28.         break