|
6 | 6 |
|
7 | 7 | # Improve this program and make it suitable for general module like use in another programs |
8 | 8 | import cv2 |
| 9 | +from colorama import Fore |
9 | 10 |
|
10 | 11 | cap = cv2.VideoCapture(0) |
11 | 12 |
|
|
17 | 18 | # FourCC is platform dependent; however, MJPG is a safe choice. |
18 | 19 | fourcc = cv2.VideoWriter_fourcc(*"MJPG") |
19 | 20 |
|
20 | | -# Create video writer object. Save file to recording.avi |
21 | | -out = cv2.VideoWriter("recording.avi", fourcc, 20.0, (frames_width, frames_height)) |
| 21 | +# exception Handling for captured video |
| 22 | +try: |
| 23 | + # 60 FPS video capture |
| 24 | + # Create video writer object. Save file to recording.avi |
| 25 | + out = cv2.VideoWriter("recording.avi", fourcc, 60.0, (frames_width, frames_height)) |
| 26 | +except(Exception) as e: |
| 27 | + print(Fore.RED, e, Fore.RESET) |
22 | 28 |
|
23 | 29 | while True: |
24 | 30 | # Capture frame-by-frame |
|
27 | 33 | if ret == True: |
28 | 34 | # Write frame to recording.avi |
29 | 35 | out.write(frame) |
30 | | - |
| 36 | + |
| 37 | + # color video output |
31 | 38 | # Our operations on the frame come here |
32 | | - gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) |
| 39 | + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA) |
33 | 40 |
|
34 | 41 | # Display the resulting frame |
35 | 42 | cv2.imshow("frame", gray) |
36 | | - if cv2.waitKey(1) & 0xFF == ord("q"): |
| 43 | + if cv2.waitKey(1) & 0xFF == ord(" "): |
37 | 44 | break |
38 | 45 |
|
39 | 46 | # When everything is done, release the capture and video writer |
40 | 47 | cap.release() |
41 | 48 | out.release() |
42 | 49 | cv2.destroyAllWindows() |
| 50 | + |
0 commit comments