Skip to content

Instantly share code, notes, and snippets.

@yokeshrana
Last active March 28, 2021 16:04
Show Gist options
  • Save yokeshrana/669f1ad52a8f683d1fa8bc1a666c60a7 to your computer and use it in GitHub Desktop.
Save yokeshrana/669f1ad52a8f683d1fa8bc1a666c60a7 to your computer and use it in GitHub Desktop.
Reading from Web Cam
import cv2
vid = cv2.VideoCapture(0) # instead of file path we will use the id of the device (webcam)
#now we define some specific parameter for the webcam
vid.set(3,640)
vid.set(4,480)
#Rest Code is same as basic video read
while vid.isOpened(): # Used to check if camera is opened or not
success,img=vid.read()
if success:
cv2.imshow("Video",img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment