Does OpenCV suppress OpenMP? - c++

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

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.

Related

installation error: 'Unable to locate package g++-4.8'

I am trying to install gcc and g++ version 4.8 to run a specific software in Ubuntu 22.04.1
when I perform
sudo apt-get install g++-4.8
it says
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package g++-4.8
E: Couldn't find any package by glob 'g++-4.8'
E: Couldn't find any package by regex 'g++-4.8'
and When I perform
sudo apt-get install gcc-4.8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'gcc-4.8-hppa64' for regex 'gcc-4.8'
The following packages were automatically installed and are no longer required:
chromium-codecs-ffmpeg-extra gstreamer1.0-vaapi i965-va-driver intel-media-va-driver libaacs0 libaom3 libass9 libavcodec58 libavformat58 libavutil56 libbdplus0 libbluray2
libbs2b0 libchromaprint1 libcodec2-1.0 libdav1d5 libflashrom1 libflite1 libftdi1-2 libgme0 libgsm1 libgstreamer-plugins-bad1.0-0 libigdgmm12 liblilv-0-0 libmfx1 libmysofa1
libnorm1 libopenmpt0 libpgm-5.3-0 libpostproc55 librabbitmq4 librubberband2 libserd-0-0 libshine3 libsnappy1v5 libsord-0-0 libsratom-0-0 libsrt1.4-gnutls libssh-gcrypt-4
libswresample3 libswscale5 libudfread0 libva-drm2 libva-wayland2 libva-x11-2 libva2 libvdpau1 libvidstab1.1 libx265-199 libxvidcore4 libzimg2 libzmq5 libzvbi-common libzvbi0
mesa-va-drivers mesa-vdpau-drivers pocketsphinx-en-us va-driver-all vdpau-driver-all
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
What could be done?
You could possibly recompile gcc 4.8.5 with the following script. However there is a lot that can go wrong depending on the machine that you are compiling it since the compiler itself depends on a large set of utilities - called the toolchain and they are tightly coupled with the machine's own system libraries, in particular the C standard library.
sudo dpkg --add-architecture i386
sudo apt update
sudo apt upgrade
sudo apt-get install gcc-multilib libstdc++6:i386
wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.bz2 --no-check-certificate
tar xf gcc-4.8.5.tar.bz2
cd gcc-4.8.5
./contrib/download_prerequisites
cd ..
sed -i -e 's/__attribute__/\/\/__attribute__/g' gcc-4.8.5/gcc/cp/cfns.h
sed -i 's/struct ucontext/ucontext_t/g' gcc-4.8.5/libgcc/config/i386/linux-unwind.h
mkdir xgcc-4.8.5
pushd xgcc-4.8.5
$PWD/../gcc-4.8.5/configure --enable-languages=c,c++ --prefix=/usr --enable-shared --enable-plugin --program-suffix=-4.8.5
make MAKEINFO="makeinfo --force" -j
sudo make install -j

Could NOT find Protobuf (missing: Protobuf_PROTOC_EXECUTABLE)

When I am doing a cmake in the build directory of the project I am getting this error. Initially I got a
protobuf-config.cmake not found
error. So I gave a path of the protobuf-config.cmake file to Protobuf_DIR. Later it started to show this new error:
CMake Error at
/opt/cmake/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137
(message): Could NOT find Protobuf (missing:
Protobuf_PROTOC_EXECUTABLE)
(found suitable version "3.6.1", minimum required is "3.0.0")
I am also attaching the error log file:
https://drive.google.com/open?id=1y7BZ6lDBtxvla7r-o188xM_FjwLqwhCx
I am doing this on Ubuntu-18 with cmake version: 3.13 and protobuf version: 3.6.1
You probably don't have the Protobuf compiler and development files installed. To fix that, run this command:
sudo apt-get install protobuf-compiler libprotobuf-dev
Alternatively, if you're building Protobuf by hand, you can't build it with the build type as RelWithDebInfo because that causes issues with the library and CMake.
Installed from apt on Ubuntu 20.04, dont have permissions to /usr/include/google
To fix: sudo chmod +Xr -R /usr/include/google
Default repositories usually contain outdated protobuf version. It is best to install it manually, from sources:
git clone --progress -b v3.10.0 https://github.com/protocolbuffers/protobuf && \
( \
cd protobuf; \
mkdir build; \
cd build; \
cmake ../cmake \
-DCMAKE_BUILD_TYPE=Release \
-Dprotobuf_BUILD_SHARED_LIBS=ON \
-Dprotobuf_BUILD_TESTS=OFF; \
make -j4 install; \
) && \
rm -rf protobuf
Quickly adding here that after installing Protobuf following this answer, I had to delete the build folder in my workspace to get cmake to run without this error :)
Hy,
list your protobuf libraries with sudo apt list | grep protobuf it should tell you what it will install by default. Run protoc --version so that you see what is recognized by default now. And after that get a version from github if needed build it and install it (this should not take to long). Then run protoc --version again.

What are the steps to build LLVM from source for Ubuntu Bionic Beaver?

Not all Kaleidoscope examples compile. Some do.
In the build process of LLVM Cmake complains "- Failed to find LLVM FileCheck"
My interest is in developing a toy compiler using LLVM - on a Ubuntu Bionic Beaver laptop, 64 bit. Therefore I needed to compile LLVM from source. The documentation says Cmake, gcc/g++, clang and zlib are required for the build. Yes, that is true. I found out the hard way this list is incomplete.
sudo apt update
sudo apt upgrade
sudo apt install -y cmake gcc g++ python build-essential opam ocaml
sudo apt install -y checkinstall python-pygments python-yaml llvm
opam init /* and say yes to creating a profile
opam config env
opam install ctypes ctypes-foreign
opam depext conf-llvm.6.0.0 /* and said Y to install
opam depext conf-m4.1 /* and said Y to install
opam depext conf-pkg-config.1.1 /* and said Y to install
sudo apt install libxml2-dev libplist-dev
sudo apt install llvm-7-tools
/*the z3 package is outdated, need to build from source:
mkdir z3 /*somewhere
git clone https://github.com/Z3Prover/z3
python scripts/mk_make.py
cd build
make
sudo checkinstall /* y and enter
cd <to sourceroot of llvm>
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build; cd build
cmake -DLLVM_TARGETS_TO_BUILD="X86" -DCMAKE_BUILD_TYPE=Release ../llvm
make -j2
Kaleidoscope examples from Chapters 3 and 8 compile fine. The output from the toy compiler resulting from Chapter 8 even does compile and link to a working program. The examples from the Chapters 2, 4, 5, 6, 7 and 9 don't compile.
You also need googletest as a shared library with current source code (27-04-2019) for it to compile. It is not stated as a requirement which was very frustrating when I had errors building llvm, clang, lld and clang extra tools.
Best place for the current code is: github.com/google/googletest
The best answer for how to build googletest is here

How to recover default boost installation on ubuntu?

I was trying to compile boost 1.62 from source on ubuntu 12.04 where the default version is 1.48. During the course of trying everything, I removed boost from /usr/include/boost and libboost* from /usr/lib using the following commands
sudo rm -r /usr/include/boost
sudo rm -r /usr/include/libboost*
I have realized that now I need the default version (1.48) for my program to work. But when I use the following command
sudo apt-get install libboost-dev-all
it seems to install the libboost, but I am not able to see any boost directory in /usr/include. Moreover, I tried compiling a few programs with cmake and it also doesn't seem to find any boost library on the system.
Is it not possible to reinstall libboost if the libraries and headers have been removed manually ?
from the ubuntu forums :
choices:
sudo apt-get install --reinstall mypackage
sudo dpkg-reconfigure mypackage
( or if the other solutions have failed:
sudo apt-get purge mypackage && sudo apt-get install mypackage
and logout/in )
give it a shot !
also if you don't see any librarie after installing one you can run :
sudo ldconfig
The above command will make ld (the dynamic libraries loader) aware of the new libraries.

Unmet dependency: xscrnsaver

when I build qtwebengine with following this steps, I get
Unmet dependency: xscrnsaver
QtWebEngine will not be built.
I cannot find xscrnsaver with sudo apt-file find xscrnsaver, and even I sudo apt-get install xscreensaver, the error still exist, how to fix it?
I find the solution, the reason is I miss libxss since I copy(from guide) following code to terminal:
sudo apt-get install libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev
libfontconfig1-dev libxss-dev
code has 2 lines, it means I doesn't install "libfontconfig1-dev libxss-dev", so the right code is:
sudo apt-get install libssl-dev libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev libfontconfig1-dev libxss-dev