安装opencv 有的时候总是会出现一些奇奇怪怪的问题,我将之前安装过程中所踩的一些坑整理了一下供大家参考,希望能够帮助到你们~
这边以安装opencv3.4.3+contrib为例
1.首先下载源码
opencv realsense下载链接:https://github.com/opencv/opencv
可以通过 Tag选择你要的版本号然后直接下载zip包或者git clone源码。
同样的方式下载contrib源码
contrib 下载链接 : https://github.com/opencv/opencv_contrib/tree/3.4.3
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
3.
3.1
cd opencv3.4.3/
mkdir build && cd build/
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \ #安装路径
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D WITH_CUDA=ON \
-D WITH_TBB=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D WITH_OPENGL=ON \
-D WITH_OPENMP=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \#contrib源码路径
-D BUILD_EXAMPLES=ON ..
这一步如果没问题则继续
如果出现:
Short Error:
CMake Error at cmake/OpenCVModule.cmake:352 (message):
Duplicated modules NAMES has been found
Call Stack (most recent call first):
cmake/OpenCVModule.cmake:370 (_assert_uniqueness)
modules/CMakeLists.txt:7 (ocv_glob_modules)
则:
cd opencv_contrib
git checkout 3.4.3 #对应你的版本号
然后重新cmake
没问题后继续
3.2
make -j4
如果一切顺利之后就直接跳3.3
如果过程中出现如下问题
1. ? opencv2/xfeature2d/cuda.hpp no such file or direcrory
解决办法:
$: find . -name "cuda.hpp"
找到文件发现存在: ./opencv-3.4.3/modules/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp 找到上述文件的全路径替换出错文件中引用cuda.hpp的位置代码即可。
2. ? boostdesc_bgm.i:No such file or directory compilation terminated.
opencv_contrib/modules/xfeatures2d/src/boostdesc.cpp:646:37: fatal error: boostdesc_bgm.i: No such file or directory
compilation terminated.
modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/build.make:94: recipe for target 'modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.o' failed
解决方法:
cd ****/opencv-3.4.3/ #进入你的opencv源码路径下
创建一个脚本:A.sh
将一下内容复制到脚本里头
#!/bin/bash
cd .cache/xfeatures2d/
cd boostdesc
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i > 0ae0675534aa318d9668f2a179c2a052-boostdesc_lbgm.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i > e6dcfa9f647779eb1ce446a8d759b6ea-boostdesc_binboost_256.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i > 98ea99d399965c03d555cef3ea502a0b-boostdesc_binboost_128.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i > 202e1b3e9fec871b04da31f7f016679f-boostdesc_binboost_064.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i > 324426a24fa56ad9c5b8e3e0b3e5303e-boostdesc_bgm_hd.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i > 232c966b13651bd0e46a1497b0852191-boostdesc_bgm_bi.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i > 0ea90e7a8f3f7876d450e4149c97c74f-boostdesc_bgm.i
cd ../vgg
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i > 151805e03568c9f490a5e3a872777b75-vgg_generated_120.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i > 7126a5d9a8884ebca5aea5d63d677225-vgg_generated_64.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i > e8d0dcd54d1bcfdc29203d011a797179-vgg_generated_48.i
curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i > 7cd47228edec52b6d82f46511af325c5-vgg_generated_80.i
然后执行脚本 sudo ./A.sh
然后重新cmake 和make -j4
3.? ......................internal compiler error:segmentation fault}}//cv::img_hash::
解决方法:将make -j4改成 make -j2 或者make就可以
3.3
sudo make install
如果一切顺利就好了,如果出现
file cannt create directory: /opencv/licenses.maybe need administrative privileges
解决方法:检查下sudo 加了么
opencv安装过程中出现的问题大多就是这些了,祝大家安装顺利~~~~