Skip to content

Instantly share code, notes, and snippets.

@VGostyuzhov
Created March 21, 2018 06:45
Show Gist options
  • Save VGostyuzhov/e6b388aebb166fb3118d7c473942bd61 to your computer and use it in GitHub Desktop.
Save VGostyuzhov/e6b388aebb166fb3118d7c473942bd61 to your computer and use it in GitHub Desktop.
Capture webcam stream using opencv2 library.
import cv2
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (1024,768))
while(True):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame, 1)
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
cap.release()
cv2.DestroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment