Is OpenCv already threaded? Is OpenCv already threaded? multithreading multithreading

Is OpenCv already threaded?


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.


OpenCV's parallel_for operations creates multiple threads to operate on. It builds a thread pool and distributes the work across it.

The number of threads is decided by setNumThreads function. Set it to zero for serial work. [ This changes based on the threading library that opencv is build with with. For some it is 1 ]

Note : I had some threading issues where I was managing my own threadpool.