cv::remap segfaults with std::thread

断了今生、忘了曾经 提交于 2019-12-04 22:52:25

OpenCV provides a parallel_for_ function that allows to easily parallel a portion of code using the parallel framework (Intel TBB, Pthreads, etc.) available on the computer.

It seems that in your case, the version of OpenCV you have is 2.4.9 with TBB used as the default parallel_for_ backend.

Here another issue with TBB called from multiple threads. The solution could be to disable TBB and use instead Pthreads (disable TBB and enable Pthreads in CMake) when building OpenCV from source.

Your solution should be fine also. With setNumThreads(0), the doc says:

If threads == 0, OpenCV will disable threading optimizations and run all it’s functions sequentially.

I guess that setNumThreads(1) should be fine also?

Unfortunately, I cannot determine exactly the source of the issue:

  • cv::remap is not thread safe in general or only with TBB?
  • an issue with the version of TBB? (not sure if this is related)
  • an issue with the version of OpenCV used?

I did two tests:

  • build OpenCV 3.2 from source on Ubuntu 16.04 with Pthreads used as parallel_for_ backend
  • build OpenCV 3.2 from source on Ubuntu 16.04 and use TBB instead

In both cases, I did not get any issues. So I hope it has been solved in newer OpenCV version or maybe in newer TBB version.

Note: you can use

std::cout << "getBuildInformation:\n" << cv::getBuildInformation() << std::endl;

to print the OpenCV information. In my second tests, I get:

Parallel framework: TBB (ver 4.4 interface 9003)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!