1# for Windows OS, this helped me out
2
3cap = cv2.VideoCapture(0)
4
5while(True):
6 # Capture frame-by-frame
7 ret, frame = cap.read()
8
9 # Our operations on the frame come here
10 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
11
12 # Display the resulting frame
13 cv2.imshow('frame',frame)
14 if cv2.waitKey(1) & 0xFF == ord('q'):
15 break
16
17# When everything done, release the capture
18cap.release()
19cv2.destroyAllWindows()
20cv2.waitKey(1)
21cv2.waitKey(1)
22cv2.waitKey(1)
23cv2.waitKey(1)