File tree 2 files changed +47
-0
lines changed
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Video Capture
2
+
3
+ An simple video capture program
4
+ Copyright (c) 2024 Ercan Ersoy
5
+
6
+ This example shows video display from first webcam.
Original file line number Diff line number Diff line change
1
+ # video Capture - An simple video capture program
2
+ # Copyright (c) 2024 Ercan Ersoy
3
+ # This file licensed under MIT License.
4
+ # Write this code using ChatGPT.
5
+
6
+ # Imports
7
+ import cv2
8
+ import sys
9
+
10
+ # Initialize video capture
11
+ capture = cv2 .VideoCapture (0 )
12
+
13
+ # Check if the webcam is opened correctly
14
+ if not capture .isOpened ():
15
+ print ("Error: Could not open webcam." , file = sys .stderr )
16
+ exit ()
17
+
18
+ # Continuously capture frames
19
+ while True :
20
+ # Read the frame
21
+ ret , frame = capture .read ()
22
+
23
+ # If frame is read correctly ret is True
24
+ if not ret :
25
+ print ("Error: Failed to capture frame." , file = sys .stderr )
26
+ break
27
+
28
+ # Display the frame
29
+ cv2 .imshow ('Frame' , frame )
30
+
31
+ key_code = cv2 .waitKey (1 )
32
+
33
+ # Break the loop if ESC is pressed
34
+ if cv2 .getWindowProperty ("Frame" , cv2 .WND_PROP_VISIBLE ) < 1 :
35
+ break
36
+
37
+ # Release the video capture object
38
+ capture .release ()
39
+
40
+ # Close windows
41
+ cv2 .destroyAllWindows ()
You can’t perform that action at this time.
0 commit comments