OpenCVinstall - Extended-Object-Detection-ROS/wiki_english GitHub Wiki

OpenCV installation

Why update

  • If you use ROS below Noetic, it is highly recommended to update OpenCV to 4th version, because earlier versions may not support such modules as DNN or tracking.
  • If you want use feature detectors which are outside of basic OpenCV.

Check version

Check preinstalled with ROS OpenCV version possibly with command:

pkg-config --modversion opencv

Note, that command shows only one installed version. If you have more than one, it is unable to check them with this command.

Download sources

cd ~
git clone https://github.com/opencv/opencv.git
cd opencv && git checkout 4.2.0
cd ~
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib && git checkout 4.2.0

Configure

cd ~/opencv && mkdir build && cd build
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=/home/opencv_contrib/modules -D OPENCV_ENABLE_NONFREE=ON -D WITH_CUDA=OFF -D BUILD_EXAMPLES=ON ..

Note: path in OPENCV_EXTRA_MODULES_PATH better be absolute.

During configuration, some errors can occur.

  • linux/videodev.h: No such file or directory compilation terminated. First check if OPENCV_EXTRA_MODULES_PATH in command afore contains correct path to opencv_contrib. If same, try
sudo apt-get install libv4l-dev
cd /usr/include/linux
sudo ln -s ../libv4l1-videodev.h videodev.h
  • No such file or directory #include <sys/videoio.h> First check if OPENCV_EXTRA_MODULES_PATH in command afore contains correct path to opencv_contrib. If same try to add to cmake command -D WITH_LIBV4L=OFF.

  • No file stdlib.h Try to add cmake command -D ENABLE_PRECOMPILED_HEADERS=OFF

Make

Find how many process are available

nproc

Make with that number of processes

make -j<NUM PROC> 

It is takes some time

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

ROS compability

TODO

Uninstall

If you want uninstall THAT opencv

cd ~/opencv/build
sudo make uninstall
⚠️ **GitHub.com Fallback** ⚠️