import cv2 # Open a video capture object cap = cv2.VideoCapture(0) while(True): # Capture frame-by-frame ret, frame = cap.read() # Display the resulting frame cv2.imshow('frame',frame) # Break the loop on 'q' key press if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture and destroy the window cap.release() cv2.destroyAllWindows()