Skip to content

Instantly share code, notes, and snippets.

@martin3000
Created September 13, 2017 07:52
Show Gist options
  • Select an option

  • Save martin3000/12096ae6e85ce3872ed465ecbea3dfad to your computer and use it in GitHub Desktop.

Select an option

Save martin3000/12096ae6e85ce3872ed465ecbea3dfad to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# capture an image every x seconds
# JMS 2017
#
WAIT=60 # sleep time in seconds
import cv2
import time
print("Press 'q' to stop.")
i=730
while True:
cap = cv2.VideoCapture(0)
cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH ,1024)
cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 576)
ret, image = cap.read()
print(ret)
cap.release() # clear buffer
if not ret:
print("ret nonzero")
break
output = "snapshot-{:08}.jpg".format(i) # 8 digits, leading zeros
cv2.imwrite(output, image)
i += 1
cv2.imshow(" ", image)
k=cv2.waitKey(1000*WAIT)
if k & 0xFF == ord('q'): # does not work, always -1
print("stop")
break
print(time.strftime("%d %b %Y %H:%M:%S",time.localtime()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment