1、ubuntu中最好先切换到root模式,docker容器则不用;以下将默认在root模式中操作,非root模式时,指令前加上sudo即可
2、安装必要依赖项
apt update
apt install build-essential cmake net-tools git vim unzip iputils-ping -y
apt install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libswresample-dev libavresample-dev libgphoto2-dev
apt install libgtk3.0 #安装过程中选 6 Asia 70 Shanghai
apt install -y libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libgstreamer1.0-dev
apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
apt install libjasper-dev
其中apt install libjasper-dev会报错,参考链接重新安装即可
3、下载opencv3.4.0,若已有安装包 此处可省略
wget https://github.com/opencv/opencv/archive/3.4.0.tar.gz
mv 3.4.0.tar.gz opencv-3.4.0.tar.gz
4、解压,并进入解压后的目录
tar -zxvf opencv-3.4.0.tar.gz
cd opencv-3.4.0
5、修改ippicv_2017u3_lnx_intel64_general_20170822.tgz下载源,进行下一步cmake编译过程中会提示:“IPPICV:Download:ippicv_2017u3_lnx_intel64_general_20170822.tgz”,很容易卡死在这里,或下载失败,这里直接直接下载好该文件,并修改opencv中下载安装路径
5.1、点击上述“下载源”,下载ippicv_2017u3_lnx_intel64_general_20170822.tgz,并将其放到 opencv-3.4.0目录中
5.2、打开ippicv.cmake文件
vi 3rdparty/ippicv/ippicv.cmake
ubuntu中可使用
gedit 3rdparty/ippicv/ippicv.cmake
5.3、将47行的 "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/" 前添加 # 注释掉,并添加一行为文件ippicv_2017u3_lnx_intel64_general_20170822.tgz所在路径,如:
47 # "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"
48 "file:///home/ippicv_2017u3_lnx_intel64_general_20170822.tgz"
6、执行cmake编译指令,若发现有其他必要组件缺失,安装该组件,重新执行该cmake指令即可
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_opencv_world=ON -D OPENCV_DNN_CUDA=OFF -D WITH_CUDA=OFF -D CMAKE_INSTALL_PREFIX=/usr/local/opencv340 ..
注意:其中,BUILD_opencv_world=ON 将所有opencv必要库绑定到libopencv_world340.so文件,工程中直接使用该 .so文件即可;
CMAKE_INSTALL_PREFIX=/usr/local/opencv340 将opencv相关安装到/usr/local/opencv340目录中,工程中注意连接该目录
7、编译安装
make -j12
make install