Skip to content

Commit 4565548

Browse files
committed
increased video Frame rate 20 to 60 and changed Video output Color format grey to color BGRA.
1 parent e1fe764 commit 4565548

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

webcam.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# Improve this program and make it suitable for general module like use in another programs
88
import cv2
9+
from colorama import Fore
910

1011
cap = cv2.VideoCapture(0)
1112

@@ -17,8 +18,13 @@
1718
# FourCC is platform dependent; however, MJPG is a safe choice.
1819
fourcc = cv2.VideoWriter_fourcc(*"MJPG")
1920

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

2329
while True:
2430
# Capture frame-by-frame
@@ -27,9 +33,10 @@
2733
if ret == True:
2834
# Write frame to recording.avi
2935
out.write(frame)
30-
36+
37+
# color video output
3138
# Our operations on the frame come here
32-
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
39+
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
3340

3441
# Display the resulting frame
3542
cv2.imshow("frame", gray)
@@ -40,3 +47,4 @@
4047
cap.release()
4148
out.release()
4249
cv2.destroyAllWindows()
50+

0 commit comments

Comments
 (0)