Ubuntu16.04卸载opencv3.2.0并源码安装opencv4.0.1与opencv_contrib4.0.1

1.卸载原有opencv

cd opencv-3.2.0/build
sudo make uninstall
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*
cd /usr
sudo find . -name "*opencv*" | xargs sudo rm -rf

2.下载opencv4.0.1与opencv_contrib4.0.1源码

 https://codeload.github.com/opencv/opencv/zip/4.0.1

https://codeload.github.com/opencv/opencv_contrib/zip/4.0.1

Ubuntu16.04卸载opencv3.2.0并源码安装opencv4.0.1与opencv_contrib4.0.1_第1张图片

unzip opencv-4.0.1.zip 
unzip opencv_contrib-4.0.1.zip

解压完后两个要放在同一级目录下(不要乱改名字)

3.源码安装opencv4.0.1与opencv_contrib4.0.1

进入到opencv-4.0.1文件夹

mkdir build
cd build

注意下面cmake,把opencv_contrib-4.0.1一块编译了

cmake -D CMAKE_BUILD_TYPE=Release \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.1/modules \ -D OPENCV_GENERATE_PKGCONFIG=YES \ -D WITH_1394=OFF ..
make -j16

 一切顺利的话会是下面那个界面(这次安装出奇的顺利,一把就好了)

Ubuntu16.04卸载opencv3.2.0并源码安装opencv4.0.1与opencv_contrib4.0.1_第2张图片

sudo make install
sudo ldconfig

添加环境变量PKG_CONFIG_PATH~/.bashrc

gedit ~/.bashrc

写入:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Ubuntu16.04卸载opencv3.2.0并源码安装opencv4.0.1与opencv_contrib4.0.1_第3张图片

source ~/.bashrc

4.验证安装

cd ../samples/cpp/example_cmake

为了避免电脑没有摄像头,修改写example.cpp第17行的源码

gedit example.cpp 

capture.open(0);改为capture.open("../../data/tree.avi");

cmake .
make

运行代码

./opencv_example

你可能感兴趣的:(系统配置与安装)