Skip to content

Instantly share code, notes, and snippets.

@vereperrot
Created December 24, 2019 08:56
Show Gist options
  • Save vereperrot/d120c6e87046abc1f16f86a4183c10ce to your computer and use it in GitHub Desktop.
Save vereperrot/d120c6e87046abc1f16f86a4183c10ce to your computer and use it in GitHub Desktop.
access webcam.py
import cv2
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False
while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break
cv2.destroyWindow("preview")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment