Skip to content

Instantly share code, notes, and snippets.

@linnil1
Created July 29, 2017 04:07
Show Gist options
  • Save linnil1/3e1dbc2abbf1765120f1f0f18d0f7ac1 to your computer and use it in GitHub Desktop.
Save linnil1/3e1dbc2abbf1765120f1f0f18d0f7ac1 to your computer and use it in GitHub Desktop.
save webcam capture image
import cv2
import numpy as np
import time
cap = cv2.VideoCapture(0)
while not cap.isOpened():
print("Reset")
time.sleep(0.1)
cap = cv2.VideoCapture(0)
try:
while(True):
ret, frame = cap.read()
randomname = time.strftime("%Y%m%d%H%M%S") + \
"{:03}".format(round(time.time() * 1000) % 1000)
cv2.imwrite("image/image_" + randomname + '.jpg', frame)
time.sleep(0.33)
finally:
cap.release()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment