import cv
import time
cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(0)
print "starting"
while True:
img = cv.QueryFrame(capture)
cv.ShowImage("camera", img)
if cv.WaitKey(10) == 32:
print "trying to save"
t = time.localtime()
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)
cv.SaveImage(filename + ".jpg", img)
print "saved"
if cv.WaitKey(10) == 27:
print "exiting"
break