1 | initial version |
As connectedComponentsWithStats
is already parallelized, it should run efficiently on your computer, no need to multithread. You'll lose more than you'll win. I tried it, and putting this function in parallel threads actually increased the processing time.
If you still need to run connectedComponentsWithStats
in concurrent threads, you have to disable the parallelization inside the function.
In the file modules/imgproc/src/connectedcomponents.cpp
(from the OpenCV source) change the line:
const bool is_parallel = currentParallelFramework != NULL && numberOfCPUs > 1 && L.rows / numberOfCPUs >= 2;
to:
const bool is_parallel = false;
and recompile/reinstall OpenCV. It will solve the problem.
2 | No.2 Revision |
As connectedComponentsWithStats
is already parallelized, it should run efficiently on your computer, no need to multithread. You'll lose more than you'll win. I tried it, and putting this function in parallel threads actually increased the processing time.
If you still need to run connectedComponentsWithStats
in concurrent threads, you have to disable the parallelization inside the function.
In the file modules/imgproc/src/connectedcomponents.cpp
(from the OpenCV source) change the line:
const bool is_parallel = currentParallelFramework != NULL && numberOfCPUs > 1 && L.rows / numberOfCPUs >= 2;
to:
const bool is_parallel = false;
and recompile/reinstall OpenCV. It will solve the problem.
[EDIT] some explanations at the end: why did I prefer to disable the internal optimizations?
In my case I'm capturing a video stream and doing different processing in parallel (let's call them A, B and C). Some are fast, and some are slower. I want each process to take the images as fast as it can. Let's say process A can take every image, process B every third image and process C every tenth image. And I don't want process C to block the other processes, so I need to run them in parallel. Originally some threads were hanging, but by disabling internal parallelization on connectedComponentsWithStats
I can run them efficiently.