You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Increase Webcam FPS with Multithreading in OpenCV C+
2
-
Status: ongoing
1
+
# Increase Webcam FPS with Multithreading in OpenCV C++
3
2
4
-
I want to improve the performance of webcam streaming using OpenCV. This [article](https://www.pyimagesearch.com/2015/12/21/increasing-webcam-fps-with-python-and-opencv/) suggesting using multithreading to improve the frame per second (FPS) rate but I'm not sure whether the perfomance difference would be significant or not. However, it worths doing some experiments though. I would be a great project to learn some new concepts on multithreading and practice coding in C++.
[](https://github.com/XAMPPRocky/tokei)
5
7
6
-
If the performance speeds up, then I would try to adding object detection feature to this project using [dlib](http://dlib.net/). I did a project using *dlib*in Python but the video speed is really bad. So I hope this project could results in some positive result!
8
+
Real‑time multithreaded webcam/video capture in modern C++20 & OpenCV that keeps your main thread free for computer vision or ML inference.
7
9
8
-
Using Docker? https://medium.com/heuristics/docker-for-c-build-pipeline-7eeaaa461f97
10
+
## Why?
9
11
10
-
## Instruction
11
-
Build and execute:
12
-
```shell
12
+
OpenCV's `VideoCapture` is synchronous: every `read()` blocks on USB/RTSP I/O and decoding. This library adds a **producer/consumer** queue so frame acquisition runs on a dedicated thread, lifting throughput up to **32%** on a 4‑core laptop while keeping latency bounded.
The detach method ```t1.detach()``` is used we don't need to wait for the thread 1 to finish. Instead, it will get the dataframe. The process happens simultaneously.
61
+
## Webcam Stream
62
+
63
+
The `detach` method (`t1.detach()`) is used so we don't need to wait for thread 1 to finish. Instead, it will get the dataframe. The process happens simultaneously.
64
+
65
+
## Measuring FPS and Elapsed Time
66
+
67
+
I first used the **chrono** library to measure the time but found that it's hard to convert to seconds for calculating FPS. So, I use **ctime**:
29
68
30
-
## Measuring FPS and Elapsed time
31
-
I first use **chrono** liberary to measure the time but found that it's hard to convert to seconds unit for calculating FPS. So, I use **ctime**.
- Inspired by [PyImageSearch: "How to increase FPS with multithreading in OpenCV"](https://www.pyimagesearch.com/2015/12/21/increasing-webcam-fps-with-python-and-opencv/)
124
+
- Ring‑buffer pattern adapted from Dmitry Vyukov’s MPSC queue.
125
+
- Thanks to all contributors and stargazers for keeping the project alive!
0 commit comments