|  | 
|  | 1 | +import cv2  | 
|  | 2 | + | 
|  | 3 | +key = cv2. waitKey(1) | 
|  | 4 | +webcam = cv2.VideoCapture(0) | 
|  | 5 | +while True: | 
|  | 6 | + | 
|  | 7 | + check, frame = webcam.read() | 
|  | 8 | + print(check) #prints true as long as the webcam is running | 
|  | 9 | + print(frame) #prints matrix values of each framecd  | 
|  | 10 | + cv2.imshow("Capturing", frame) | 
|  | 11 | + key = cv2.waitKey(1) | 
|  | 12 | + if key == ord('s'):  | 
|  | 13 | + cv2.imwrite(filename='saved_img.jpg', img=frame) | 
|  | 14 | + | 
|  | 15 | + break | 
|  | 16 | + elif key == ord('q'): | 
|  | 17 | + break | 
|  | 18 | +webcam.release() | 
|  | 19 | +img_new = cv2.imread('saved_img.jpg', cv2.IMREAD_GRAYSCALE) | 
|  | 20 | +img_new = cv2.imshow("Captured Image", img_new) | 
|  | 21 | +cv2.waitKey(1650) | 
|  | 22 | +cv2.destroyAllWindows() | 
|  | 23 | + | 
|  | 24 | +img_ = cv2.imread('saved_img.jpg', cv2.IMREAD_ANYCOLOR) | 
|  | 25 | +gray = cv2.cvtColor(img_, cv2.COLOR_BGR2GRAY) | 
|  | 26 | +img_ = cv2.resize(gray,(28,28)) | 
|  | 27 | +img_resized = cv2.imwrite(filename='saved_img-final.jpg', img=img_) | 
0 commit comments