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()