Created
October 30, 2019 19:01
-
-
Save grohith327/becb9a96274d04a8e97cac5a6e23abdf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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