1.文件下载
OpenCV版本源码gitee快速下载方法
git clone -b 3.4.13 https://gitee.com/mirrors/opencv.git
git clone -b 3.4.13 https://gitee.com/mirrors/opencv_contrib.git
只需把上面-b后面的版本号改成对应版本号即可
2.安装依赖项
安装以下依赖包
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 build-essential qt5-default ccache libv4l-dev libavresample-dev libgphoto2-dev libopenblas-base libopenblas-dev doxygen openjdk-8-jdk pylint libvtk6-dev
sudo apt-get install pkg-config
可能会遇到安装libjasper-dev依赖包错误:E: Unable to locate package libjasper-dev 解决办法:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
3.编译
- 解压下载的安装包
unzip opencv-3.4.13.zip
unzip opencv_contrib-3.4.13.zip
- 将opencv_contrib.zip提取到opencv目录下,同时新建一个build文件夹
cp -r opencv_contrib-3.4.13 opencv-3.4.13
cd opencv-3.4.13
mkdir build
- 进入build,执行cmake生成makefile文件
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D WITH_CUDA=OFF -D BUILD_DOCS=OFF -D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TIFF=ON \
OPENCV_EXTRA_MODULES_PATH=/home/zhan/Lib/opencv-3.4.13/opencv_contrib-3.4.13/modules/ ..
注:OPENCV_EXTRA_MODULES_PATH是opencv_contrib-3.4.13下面文件夹modules的路径,请按照自己的实际目录修改地址,后面的两点不可省略。
- make进行编译
sudo make -j12
sudo make install
- 链接库共享
编译安装完毕之后,为了让你的链接库被系统共享,让编译器发现,需要执行管理命令ldconfig:
sudo ldconfig -v
|