1import cv2
2
3cap = cv2.VideoCapture(0)
4
5while True:
6 ret, frame = cap.read()
7
8 cv2.imshow('webcam feed' , frame)
9 if cv2.waitKey(1) & 0xFF == ord(' '):
10 break
11
12cap.release()
13cv2.destroyAllWindows()
14
15#by using the spacebar you will be able to finish the process of video capturing
16#in opencv and the window will close
1import cv2
2cap = cv2.VideoCapture()
3# The device number might be 0 or 1 depending on the device and the webcam
4cap.open(0, cv2.CAP_DSHOW)
5while(True):
6 ret, frame = cap.read()
7 cv2.imshow('frame', frame)
8 if cv2.waitKey(1) & 0xFF == ord('q'):
9 break
10cap.release()
11cv2.destroyAllWindows()
1import numpy as np
2import cv2
3
4cap = cv2.VideoCapture(0)
5
6while(True):
7 # Capture frame-by-frame
8 ret, frame = cap.read()
9
10 # Our operations on the frame come here
11 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
12
13 # Display the resulting frame
14 cv2.imshow('frame',gray)
15 if cv2.waitKey(1) & 0xFF == ord('q'):
16 break
17
18# When everything done, release the capture
19cap.release()
20cv2.destroyAllWindows()
21