ubuntu安装与卸载opencv与opencv_contrib

最近要用到CSRT跟踪器,要求opencv_contrib版本3.4.2及其以上,记录下安装过程(之前opencv和opencv_contrib版本都是3.4.0)

零、安装依赖项

注:只是更新版本的请忽略

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
sudo apt-get install cmake-gui

一、下载对应版本opencv和opencv_contrib

opencv: https://opencv.org/
opencv_contrib: https://github.com/opencv/opencv_contrib/releases
opencv在右上角release中找到并下载对应版本source zip,opencv_contrib也下载压缩文件,且保证与opencv版本相同

二、卸载老版本opencv

找到之前安装opencv的build目录

cd OpenCV_ROOT/build
sudo make uninstall
cd  ..
sudo rm -rf build

删除残留系统中的opencv文件

sudo rm -rf /usr/local/include/opencv*
sudo rm -rf /usr/include/opencv*
sudo rm -rf /usr/local/share/opencv 
sudo rm -rf /usr/local/share/OpenCV 
sudo rm -rf /usr/share/opencv 
sudo rm -rf /usr/share/OpenCV
sudo rm -rf /usr/local/bin/opencv* 
sudo rm -rf /usr/local/lib/libopencv*
sudo rm -rf /usr/share/doc/libopencv*
sudo rm -rf /usr/share/doc/opencv*
sudo rm -rf /usr/share/lintian/overrides/libopencv*
sudo rm -rf /usr/lib/x86_64-linux-gnu/libopencv*
sudo rm -rf /var/lib/dpkg/info/libopencv*
sudo rm -rf /usr/lib/jni/libopencv*
sudo rm -rf /usr/bin/opencv*
sudo rm -rf /usr/share/lintian/overrides/libopencv*
sudo rm -rf /usr/share/java/opencv*

三、安装前配置

解压刚下载的opencv和opencv_contrib,并将opencv_contrib加压至opencv文件夹中,并改名为contrib(其实随便,不改名也行,这样显得规整一些)

#进入opencv文件夹
cd OpenCV_NEW_ROOT
mkdir build
cmake-gui

where is the source code选择opencv文件夹,where to build the binaries选择刚建立的build文件
ubuntu安装与卸载opencv与opencv_contrib_第1张图片
点击Configure,后点finish

等待一段时间显示:Configuring done后
ubuntu安装与卸载opencv与opencv_contrib_第2张图片
修改两处内容:

在CMAKE_BUILD_TYPE 值处输入RELEASE

在OPENCV_EXTRA_MODULES_PATH处选择contrib里的module文件夹路径(记得一定是contrib里的module的路径,不是contrib的)

ubuntu安装与卸载opencv与opencv_contrib_第3张图片
之后点击Generate

四、安装

#在build文件夹中
make
sudo make install

安装完毕

你可能感兴趣的:(计算机视觉,opencv,深度学习)