commit 9744526b875bc63395aef971b97af700ab2eaa2c Author: talksik Date: Wed Jun 28 14:43:21 2023 -0700 adding in initial code diff --git a/main.py b/main.py new file mode 100644 index 0000000..68b4462 --- /dev/null +++ b/main.py @@ -0,0 +1,33 @@ +import cv2 + +# Create a VideoCapture object to capture video from the camera +cap = cv2.VideoCapture(0) # Use 0 for the default camera + +# Check if the camera is opened successfully +if not cap.isOpened(): + print("Failed to open the camera") + exit() + +# Create a window to display the captured video +cv2.namedWindow("Video", cv2.WINDOW_NORMAL) + +# Read and display frames from the camera until the user presses 'q' +while True: + # Read a frame from the camera + ret, frame = cap.read() + + # Check if a frame was successfully read + if not ret: + print("Failed to read a frame from the camera") + break + + # Display the frame in the "Video" window + cv2.imshow("Video", frame) + + # Wait for the user to press 'q' to exit + if cv2.waitKey(1) & 0xFF == ord('q'): + break + +# Release the VideoCapture object and close the display window +cap.release() +cv2.destroyAllWindows()