Skip to content

opencv_contrib_noetic_install

Moscowsky Anton edited this page Mar 31, 2021 · 7 revisions

Installing OpenCV contrib on ROS Noetic

OpenCV contrib is an add-on to OpenCV, not included in the version of the library that is came with ROS. However, this part contains a number of useful implementations, incl. detection using key points (methods SIFT, SURF, ORB, etc.).

1. Install

To install this module, however, you have to reinstall the entire OpenCV (in any case, I have not found a reliable way to do otherwise). For this:

  1. Create a directory where the sources will be placed
cd
mkdir Libs
cd Libs
  1. Download OpenCV and OpenCV contrib
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
  1. Checkout in both repositories to version we need, for ROS Noetic this is 4.2.0
cd opencv_contrib
git checkout 4.2.0
cd ../opencv
git checkout 4.2.0
  1. Create build directory
mkdir build
cd build
  1. Configure Watch the parameters, OPENCV_EXTRA_MODULES_PATH must contain the correct path to the modules folder of the opencv_contrib package. See for CUDA build (in process).
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D OPENCV_EXTRA_MODULES_PATH=~/Libs/opencv_contrib/modules -D OPENCV_ENABLE_NONFREE=ON -D WITH_CUDA=OFF -D BUILD_EXAMPLES=ON ..
  1. If the configuration was successful, then we collect. Find out how many processes are available
nproc

Make with an indication of the number of available processes.

make -j<NUM PROC> 

For example

make -j4

This is a rather lengthy operation. At its end, we carry out the final steps.

sudo make install
sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

2. Package customization

Then, to build Extended Object Detection based on OpenCV contrib, you need to replace the line in the CMakeLists.txt file located in the root of the repository

set(opencv_contrib OFF)

to

set(opencv_contrib ON)

And build the project. If the project has already been built before, then you may need to delete the collected files. The most reliable, but at the same time barbaric, way to do this is to delete the build and devel folders of your workspace and rebuild it entirely.

During assembly, this type of vornings may appear

runtime library [libopencv_calib3d.so.4.2] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /usr/local/lib

Don't pay attention to them.

Clone this wiki locally