This project provides a simple code snippet to capture images from a webcam using OpenCV in Python. It utilizes the OpenCV library to access the webcam, capture frames, and save them as JPEG images.
- Accesses the webcam and captures frames in real-time.
- Saves captured frames as JPEG images with unique filenames based on timestamps.
- Provides a basic implementation that can be easily integrated into larger projects.
To run this code, you need to have OpenCV installed. You can install OpenCV using:
pip install opencv-python
- Import the necessary libraries: cv2 and time.
- Create a VideoCapture object to access the webcam.
- Set up a loop to continuously capture frames from the webcam.
- Generate a unique filename for each captured frame based on the current timestamp.
- Save the captured frame as a JPEG image using the imwrite() function from OpenCV.
- Set the loop termination condition as needed.
- Release the webcam resource using the release() method of the VideoCapture object.
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.