目录
1 依赖安装
2 下载opencv3.4.5及opencv3.4.5 contrib版本
3 编译opencv3.4.5 opencv3.4.5_contrib及遇到的问题
1 依赖安装
首先安装编译工具CMake,命令安装即可:
sudo apt install cmake
安装Eigen:
sudo apt-get install libeigen3-dev
将Eigen放到程序可以找到的地方:
cd /usr/include/eigen3 sudo cp Eigen/ .. -R
安装opencv依赖:
sudo apt-get install libglew-dev sudo apt-get install libboost-dev libboost-thread-dev sudo apt-get install libboost-filesystem-dev sudo apt-get install libpython2.7-dev 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 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的时候会出现下图问题:
执行下面的命令:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" sudo apt update sudo apt install libjasper1 libjasper-dev
即可完成安装。
2 下载opencv3.4.5及opencv3.4.5 contrib版本
opencv3.4.5下载链接:
https://github.com/opencv/opencv/releases/tag/3.4.5https://github.com/opencv/opencv/releases/tag/3.4.5 opencv3.4.5 contirb下载链接:
Release 3.4.5 · opencv/opencv_contrib · GitHubRepository for OpenCV's extra modules. Contribute to opencv/opencv_contrib development by creating an account on GitHub.https://github.com/opencv/opencv_contrib/releases/tag/3.4.5 我们解压这两个文件,将opencv3.4.5_contrib放到opencv3.4.5的文件夹中,如图:
3 编译opencv3.4.5 opencv3.4.5_contrib及遇到的问题
我们建立build文件夹,在build文件夹下面输入如下命令:
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-3.4.5 -D OPENCV_EXTRA_MODULES_PATH=/bag/opencv-3.4.5/opencv_contrib-3.4.5/modules/ -D OPENCV_ENABLE_NONFREE=True ..
这个一定不能省略.....
出现这个界面表示配置完成:
编译opencv:
make -j
然后出现第一个问题:
我们找到这个文件:
将47行改成这个:
# include </usr/include/eigen3/unsupported/Eigen/MatrixFunctions>
再进行编译:
然后出现第二个问题:
这是由于opencv_contrib缺少文件导致的:
boostdesc_bgm.i boostdesc_bgm_bi.i boostdesc_bgm_hd.i boostdesc_lbgm.i boostdesc_binboost_064.i boostdesc_binboost_128.i boostdesc_binboost_256.i vgg_generated_120.i vgg_generated_64.i vgg_generated_80.i vgg_generated_48.i
这个是由于缺少文件,我上传到了这个链接处:
https://download.csdn.net/download/qq_41694024/88407734https://download.csdn.net/download/qq_41694024/88407734 我们把这些文件保存到OpenCV源码根目录的隐藏文件夹.cache/xfeatures2d/下面:
还有这个文件夹下:
编译:遇到找不到cuda的问题:
我们在系统中寻找这个文件:
liuhongwei@liuhongwei-Legion-Y9000P-IRX8H:/bag/opencv-3.4.5/build$ sudo updatedb[sudo] password for liuhongwei: liuhongwei@liuhongwei-Legion-Y9000P-IRX8H:/bag/opencv-3.4.5/build$ locate cuda.hpp /bag/opencv-3.4.15/modules/core/include/opencv2/core/cuda.hpp /bag/opencv-3.4.15/modules/core/include/opencv2/core/private.cuda.hpp /bag/opencv-3.4.15/modules/photo/include/opencv2/photo/cuda.hpp /bag/opencv-3.4.5/modules/core/include/opencv2/core/cuda.hpp /bag/opencv-3.4.5/modules/core/include/opencv2/core/private.cuda.hpp /bag/opencv-3.4.5/modules/photo/include/opencv2/photo/cuda.hpp /bag/opencv-3.4.5/opencv_contrib-3.4.5/modules/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp /bag/pcl-pcl-1.8.0/gpu/utils/include/pcl/gpu/utils/timers_cuda.hpp /usr/include/opencv2/core/cuda.hpp /usr/include/opencv2/core/private.cuda.hpp /usr/include/opencv2/photo/cuda.hpp
改成绝对路径:
这个错误也是一样的:
在这个路径下:
都是这么处理的:
成功了:
安装即可: