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. print "starting"
  8. while True:
  9.     img = cv.QueryFrame(capture)
  10.     cv.ShowImage("camera", img)
  11.     if cv.WaitKey(10) == 32:
  12.         print "trying to save"
  13.         t = time.localtime()
  14.         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)
  15.         cv.SaveImage(filename + ".jpg", img)
  16.         print "saved"
  17.  
  18.     if cv.WaitKey(10) == 27:
  19.         print "exiting"
  20.         break