sudo apt-get update
sudo apt-get upgrade
sudo apt-get install cmake
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
这一步出现无法定位软件包 libjasper-dev
解决办法:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
下载opencv压缩包
wget https://github.com/opencv/opencv/archive/3.4.0.zip -O opencv-3.4.0.zip
wget https://github.com/opencv/opencv_contrib/archive/3.4.0.zip -O opencv_contrib-3.4.0.zip
解压后,将opencv_contrib-3.4.0放在opencv-3.4.0文件夹下
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/zhw/3rdparty/opencv-3.4.0/opencv_contrib-3.4.0/modules/ ..
(这里有个步骤会下载失败,不影响安装)
make -j16
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
空白文件中添加/usr/local/lib
sudo ldconfig
sudo gedit /etc/bash.bashrc
末尾添加两行
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source /etc/bash.bashrc
sudo updatedb
检验是否安装成功
cd ~/3rdparty/opencv-3.4.0/samples/cpp/example_cmake
cmake .
make -j16
./opencv_example
查看版本
pkg-config opencv --modversion