Search code examples
c++opencvopenmp

Does OpenCV suppress OpenMP?


I got a question concerning OpenCV and OpenMP.

I used to parallelize my code using OpenMP, since I have to do some heavy computing on large images. Up to now (I did not use OpenCV so far) the parallelization worked fine for me.

Then I needed some functionality of the OpenCV library. Since I incorporated OCV in my code, the parallelization no longer works. Allthough I am NOT parallelizing any OCV functions. Moreover, even if I only link in the OCV libraries (core, imgproc, imgcodecs), parallelization does not work anymore.

So, how can that be? And how can I enable the parallelization (again)?

I use OpenCV 4.1 on a OpenSuSE 15.1 system. IDE is Code::Blocks. All libraries where installed from official repos (meaning: I have no clou how to work with cmake...).

Could anybody give me a hint, how to fix this?

Thank you

Phtagen


Solution

  • This installation guide assumes that the OS is Ubuntu. I post it because it will probably help solving your problem.

    Install OpenCV dependencies.

    sudo apt-get install build-essential
    sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
    sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libv4l-dev
    sudo apt-get install libcanberra-gtk-module libcanberra-gtk3-module
    

    Download the source code of the OpenCV version you like with some extra modules.

    CV_DISTRO=3.4.0
    git clone --branch $CV_DISTRO https://github.com/opencv/opencv.git opencv_$CV_DISTRO --depth 1
    git clone --branch $CV_DISTRO https://github.com/opencv/opencv_contrib.git opencv_contrib_$CV_DISTRO --depth 1
    

    Then build OpenCV.

    cd opencv_$CV_DISTRO
    mkdir -p build
    cd build/
    cmake -D CMAKE_BUILD_TYPE=Release \
        -D CMAKE_INSTALL_PREFIX=/usr/local \
        -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib_$CV_DISTRO/modules \
        -D WITH_TBB=ON \
        -D OPENCV_ENABLE_NONFREE=ON \
        -D WITH_OPENMP=ON ..
    make -j7
    sudo make install
    sudo ldconfig
    

    Feel free to edit this post.