I want to use OpenCV in order to record a video and send it as a stream. I'm a beginner and I need to know if OpenCV blocks the main thread or is it threaded itself ?
I read OpenCV documentation (2.4.9) and I couldn't find any answer.
Thanks for reading.
If you use OpenCV library beware that it spawns multiple threads for image processing internally. For example, cv. VideoCapture() spawns multiple threads internally. General rule of thumb is, your app should be spawning that many threads as the cores it has available for processing.
OpenCV is Thread Safe.
I known that OpenCV has parallelism capabilities in the form of multithreading.
Threading Building Blocks (TBB) is a C++ template library developed by Intel for writing software programs that take advantage of multi-core processors. OpenCV has a provided a simple API to take advantage of TBB.
OpenCV can spawn threads when you call a function. However, all the work is performed before control is returned to the calling thread. For a number of reasons, asynchronous processing would add a substantial extra bit of complexity. (Consider, for instance: How would your program know when the computation was done?) It would also introduce some undesired overhead if the program didn't need to be asynchronous.
You can do asynchronous processing yourself with a minimal amount of effort, though, with C++11's threading API.
OpenCV can be built with OpenMP support to make the compute functions use all the available cores on your machine. It can be built also with OpenCL and CUDA. In addition it has sorts of SIMD optimization flags.
If you don't build it with such support it will run single threaded.
In either versions, calling an OpenCV function blocks the launcher thread until it computes all the operations. That is true even when offloading the computation to a GPU.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With