第零步:
原有OpenCV的卸载,好多文章提到了build目录,需要执行 sudo make uninstall 如果没有,还需要重新安装云云,感觉应该可以,毕竟好多博客中都这样写了,但是只用一个方法,就行全局搜索,然后删除,简单粗暴!
步骤1: 查看目前安装的OpenCV版本:
pkg-config --modversion opencv
步骤2:查找所有关于OpenCV的文件
sudo find / -iname "*opencv*"
看着比较多,其实删除几个文件夹就OK:
sudo rm -rf /usr/local/lib/libopencv_*
sudo rm -rf /usr/local/include/opencv
sudo rm -rf /usr/local/include/opencv2
第一步:同时编译opencv以及opencv_contrib:
1.解压下载好的包:
unzip opencv-3.3.1.zip
unzip opencv_contrib-3.3.1.zip
2.解压完后需要将opencv_contrib.zip提取到opencv目录下,同时在该目录下新建一个文件夹build:
cp -r opencv_contrib-3.3.1 opencv-3.3.1 #复制opencv_contrib到opencv目录下
cd opencv-3.3.1
mkdir build #新建文件夹build
3.编译命令:cmake -DENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_BUILD_TYPE=Release -DBUILD_TIFF=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/airobot/opencv-3.4.3/opencv_contrib-3.4.3/modules/ ..
参考网址https://blog.csdn.net/xiangxianghehe/article/details/78780269
第二步:编译过程中报错eigen与opencv的版本不符合,这时最好安装与opencv3.3相同版本的eigen3.3,安装方式sudo apt install libeigen3-dev
-
//若默认安装的是/usr/local/include/eigen3/Eigen 下,将Eigen文件夹拷贝一份到/usr/local/include 下
-
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include
参考链接 https://blog.csdn.net/p942005405/article/details/100653731
第三步编译OpenCV提示opencv_contrib缺少boostdesc_bgm.i等文件
~/opencv_contrib/modules/xfeatures2d/src/boostdesc.cpp:673:20: fatal error: boostdesc_bgm.i: No such file or directory
下载文件后直接拷贝到opencv_contrib/modules/xfeatures2d/src/ 路径下即可
参考链接:https://www.cnblogs.com/arxive/p/11778731.html
第四步:编译OPENCV3.4.6出现 FATAL ERROR: OPENCV2/XFEATURES2D/CUDA.HPP: NO SUCH FILE OR DIRECTORY
INCLUDE_DIRECTORIES("/home/open/opencv/opencv-3.4/opencv_contrib/modules/xfeatures2d/include/opencv2")
参考网址:https://www.codenong.com/cs106654012/
解决方案:
1.cd /usr/lib/x86_64-linux-gnu
2.sudo ln -s ~/anaconda3/lib/libpcre.so.1
3.sudo ldconfig
第六步:error: ‘Vector‘ is not a member of ‘Eigen‘
解决方法
- 在matrix.h 中加上Vector的定义
template <typename Type, int Size>
using Vector = Matrix<Type, Size, 1>;