-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebcamVideoCapture.py
More file actions
41 lines (29 loc) · 1.27 KB
/
WebcamVideoCapture.py
File metadata and controls
41 lines (29 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import cv2
def main():
windowName = "Live Webcam Video Feed Capture"
cv2.namedWindow(windowName)
cap = cv2.VideoCapture(0)
'''
We need to create a 'VideoWriter' object.
'''
filename = 'D:\\CODES\\OpenCV3\\OUTPUT\\WebcamVidRec.avi'
codec = cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')
framerate = 30
resolution = (640, 480)
VideoFileOutput = cv2.VideoWriter(filename, codec, framerate, resolution) #Here, we need to pass the appropriate parameters. All arguments can be written in th form of parameters also.
if cap.isOpened():
ret, frame = cap.read()
else:
ret = False
while ret:
ret, frame = cap.read()
#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) #Using colorspace
VideoFileOutput.write(frame) #In this object, we need to pass the current frame as argument in order for the function to write on thee disc.
cv2.imshow(windowName, frame)
if cv2.waitKey(1) == 27: #Waits for 'Esc' key
break
cv2.destroyAllWindows()
VideoFileOutput.release() #In this object, we need to close the file when we exit the program.
cap.release()
if __name__ == "__main__":
main()