[Opencv uninstall and reinstall] under NVIDIA Xavier NX, uninstall opencv3 and reinstall opencv4

Posted by ankhmor on Wed, 17 Nov 2021 11:09:55 +0100

preface

Due to the requirements for OpenCV version, you need to uninstall OpenCV3.4 and reinstall version 4.4.0.

Note: ROS originally had its own OpenCV. Remember not to delete it, but only delete your own additional library, otherwise some function packages in ROS will collapse because you can't find the original OpenCV.

I can't find the original version. It may be deleted. Solve the problems later. The original problems are one after another, and then one after another

1, OpenCV3.4 full uninstall

  1. Enter the build folder where opencv was originally compiled
sudo make uninstall
  1. Return to superior
cd ..
  1. Delete build folder
sudo rm -r build
  1. Delete other opencv related files
sudo rm -r /usr/local/include/opencv2 
sudo rm -r /usr/local/include/opencv 

sudo rm -r /usr/include/opencv
sudo rm -r /usr/include/opencv2 

sudo rm -r /usr/local/share/opencv 
sudo rm -r /usr/local/share/OpenCV 

sudo rm -r /usr/share/opencv 
sudo rm -r /usr/share/OpenCV 

sudo rm -r /usr/local/bin/opencv* 
sudo rm -r /usr/local/lib/libopencv*

sudo rm -r usr/bin/opencv* 
sudo rm -r /usr/lib/libopencv*

Note: for opencv2 in the first four lines of commands, some may have named opencv4 themselves. Just delete the folder related to opencv in the relevant directory.

  1. Check whether it is completely deleted
pkg-config opencv --libs
pkg-config opencv --modversion

No package 'opencv' found appears.

If additional information appears:

sudo apt-get autoremove opencv-doc opencv-data libopencv-dev libopencv2.4-java libopencv2.4-jni python-opencv libopencv-core2.4 libopencv-gpu2.4 libopencv-ts2.4 libopencv-photo2.4 libopencv-contrib2.4 libopencv-imgproc2.4 libopencv-superres2.4 libopencv-stitching2.4 libopencv-ocl2.4 libopencv-legacy2.4 libopencv-ml2.4 libopencv-video2.4 libopencv-videostab2.4 libopencv-objdetect2.4 libopencv-calib3d2.4
  1. Remember to delete the original opencv folder.

Reference: CSDN@AI Bacteria

2, Install OpenCV (take 4.4.0 as an example)

1. Download the installation package of the corresponding version of OpenCV from the official website

opencv: https://opencv.org/releases/
opencv_contrib: https://github.com/opencv/opencv_contrib

2. Unzip it to the opencv folder and create a new build folder

mkdir build

3. Installation dependency

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 libjasper-dev libdc1394-22-dev

Problem: unable to locate package libjasper dev
Solution: (mainly Ubuntu ports under arm architecture. This step will cause the previous source to disappear. Remember to save it first)

sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe"
sudo apt update
sudo apt install libjasper1 libjasper-dev

Reference: CSDN@rrr2

4. Enter the build folder to compile and install (there will be problems for the first time)

cd ~/opencv/build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules/ ..

Note:
① / usr/local is the path to install by default
② OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules /... Refers to OpenCV_ The path of modules in contrib3.4.0. The following two points cannot be omitted

After cmake, there should be some file download failures, which is due to the problems of walls and contrib. If these files are not solved, make and install will fail later.

Question 1: fatal error: bootdesc_ bgm.i: No such file or directory

Screenshots of some error examples are as follows (the system only prompts one, in fact, the second picture is missing):

resolvent:
step1: according to the website in CmakeDownload.txt file, you can "surf the Internet scientifically" or modify the name from the resources downloaded by others and put it into the corresponding folder. For details, please refer to me Tutorial for installing contrib of OpenCV4 under Windows , I won't repeat it here.


My missing file with MD5 value.

Step 2: remove the prefix from the following 11 files without MD5 value and put them in / home/opencv/opencv_contrib/modules/xfeatures2d/src path (make appropriate changes according to your contrib path. This is my path).
The file name without MD5 value is as follows:

boostdesc_bgm.i
boostdesc_bgm_bi.i
boostdesc_bgm_hd.i
boostdesc_lbgm.i
boostdesc_binboost_064.i
boostdesc_binboost_128.i
boostdesc_binboost_256.i
vgg_generated_120.i
vgg_generated_64.i
vgg_generated_80.i
vgg_generated_48.i

step3: recompile and install (Note: cmake you have to configure it again).

make -j4			// Audit depends on your own platform
sudo make install

Note: xdjm, read it clearly and then operate it. There are a lot of comments in the comment area of that article that fail to follow the steps or fail to install it carelessly.

Question 2: fatal error: features2d/test/test_detectors_regression.impl.hpp: No such file or directory


Solution: copy opencv / modules / features2d directly and paste it into the build directory to solve this problem.

Finally, compile again:

make -j4			// Audit depends on your own platform
sudo make install

Reference: CSDN@HeyMountain,@g_grace1,@Little Mr. Xie

summary

Even after the installation, there is no suitable program to test whether contrib can be used normally. I hope dalao will point out where it is when he passes by.

Topics: C C++ OpenCV slam