https://github.com/nick8592/opencv-framebuffer
This project captures live video from the default camera, stores the last 10 frames in a buffer, calculates and displays the FPS (Frames Per Second), and prints memory addresses of the frames. It uses OpenCV for video capture and processing, providing a simple example of real-time video processing and frame management.
https://github.com/nick8592/opencv-framebuffer
cpp opencv
Last synced: about 2 months ago
JSON representation
This project captures live video from the default camera, stores the last 10 frames in a buffer, calculates and displays the FPS (Frames Per Second), and prints memory addresses of the frames. It uses OpenCV for video capture and processing, providing a simple example of real-time video processing and frame management.
- Host: GitHub
- URL: https://github.com/nick8592/opencv-framebuffer
- Owner: nick8592
- Created: 2025-02-24T08:25:18.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-24T09:26:26.000Z (over 1 year ago)
- Last Synced: 2025-09-24T00:26:38.684Z (9 months ago)
- Topics: cpp, opencv
- Language: C++
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OpenCV Frame Buffer Example
This project demonstrates how to capture video from the default camera, store the last 10 frames in a buffer, calculate and display the FPS (Frames Per Second), and print memory addresses of the frames in the buffer.
## Requirements
- **C++ Compiler** (e.g., GCC)
- **OpenCV** library (for computer vision tasks)
### Installation of OpenCV
Follow the instructions below to install OpenCV for your platform.
#### On Ubuntu:
```bash
sudo apt update
sudo apt install libopencv-dev
```
### Building the Code
To build and compile this C++ program, follow the steps below:
1. Ensure OpenCV is installed and configured correctly on your system.
2. Clone this repository.
```bash
git clone https://github.com/nick8592/opencv_framebuffer.git
```
3. Navigate to the directory.
```bash
cd opencv-framebuffer
```
4. Build the project:
```bash
g++ -o capture_and_display capture_and_display.cpp `pkg-config --cflags --libs opencv4`
```
This will generate an executable called `capture_and_display` in the `opencv_framebuffer` directory.
### Running the Code
After building the program, run it with the following command:
```bash
./capture_and_display
```
The program will open the default camera, display the live camera feed in a window, and print the following in the terminal:
- **FPS (Frames per second)**: The real-time frame rate calculated based on the time between frames.
- **Memory addresses** of the frames stored in the buffer.
You can press the **Ctrl+C** key at any time to quit the program.
### Code Explanation
- **OpenCV VideoCapture**: Captures the frames from the default camera (camera index `0`).
- **cv::Mat**: Used to store the captured frames as matrices.
- **frameBuffer**: A vector storing the last 10 frames.
- **FPS Calculation**: Uses `cv::getTickCount()` to calculate the FPS in real-time.
- **Memory Addresses**: Prints the memory addresses of the stored frames and their raw data.
### Example Output
```bash
FPS: 30.2563
Printing memory addresses of frames in the buffer:
Address of frame 1 (cv::Mat object): 0x7f8f6a0f23f0
Address of raw data (frameBuffer[0].data): 0x7f8f6a0f2400
Address of frame 2 (cv::Mat object): 0x7f8f6a0f23b0
Address of raw data (frameBuffer[1].data): 0x7f8f6a0f2400
...
```