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