# capture a video and write it to drive
import cv2
cap = cv2.VideoCapture(0)
window_name='camera'
cv2.namedWindow(window_name,cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(window_name,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 30.0, (640,480)) # capture 30 frame per second
# video resolution 640x480
while (True):
ret, frame = cap.read()
cv2.imshow(window_name,frame)
out.write(frame)
if cv2.waitKey(1) & 0xFF == ord('q'): # btw, you need to click the screen first. And then
# press q to quit
break
cap.release()
out.release()
cv2.destroyAllWindows()