1import cv2
2
3cap = cv2.VideoCapture(0)
4
5# Check if the webcam is opened correctly
6if not cap.isOpened():
7 raise IOError("Cannot open webcam")
8
9while True:
10 ret, frame = cap.read()
11 frame = cv2.resize(frame, None, fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
12 cv2.imshow('Input', frame)
13
14 c = cv2.waitKey(1)
15 if c == 27:
16 break
17
18cap.release()
19cv2.destroyAllWindows()
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 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
1import cv2
2frameWidth = 640
3frameHeight = 480
4cap = cv2.VideoCapture(0)
5cap.set(3, frameWidth)
6cap.set(4, frameHeight)
7cap.set(10,150)
8while True:
9 success, img = cap.read()
10 cv2.imshow("Result", img)
11 if cv2.waitKey(1) and 0xFF == ord('q'):
12 break
13