Skip to content

Instantly share code, notes, and snippets.

@grohith327
Created October 30, 2019 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grohith327/becb9a96274d04a8e97cac5a6e23abdf to your computer and use it in GitHub Desktop.
Save grohith327/becb9a96274d04a8e97cac5a6e23abdf to your computer and use it in GitHub Desktop.
import cv2
cam = cv2.VideoCapture(0)
cv2.namedWindow("take a picture")
img_counter = 0
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
if not ret:
break
k = cv2.waitKey(1)
if k%256 == 27:
print("Escape hit, closing...")
break
elif k%256 == 32:
img_name = "opencv_frame_{}.png".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
cam.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment