在精简版我只会介绍如何安装,关于碰到的问题和如何解决不会提及。
如果你理解安装,并只是想要
ippicv
face_landmark_model.dat
xfeatures2d/vgg
xfeatures2d/boostdesc
等文件,甚至下面内容都不用看,直接看下面提供了下载链接,并且已经改完名字了
sudo apt-get update
sudo apt-get upgrade
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
/home/zjh/tools/
opencv-3.4
opencv_contrib-3.4
data ippicv xfeatures2d //这3个是cache解压文件
cd opencv-3.4/
ls -a #没有.cache继续下一步否则不用
mkdir .cache
cp -r data /home/zjh/tools/opencv-3.4/.cache
cp -r ippicv /home/zjh/tools/opencv-3.4/.cache
cp -r xfeatures2d /home/zjh/tools/opencv-3.4/.cache
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/zjh/tools/opencv_contrib-3.4/modules/ ..
根据自己要求修改
必改:的为OPENCV_EXTRA_MODULES_PATH 参数,请根据自己的路径将参数
OPENCV_EXTRA_MODULES_PATH= /home/zjh/tools/opencv_contrib-3.4/modules/
后面的路径修改为自己的contrib目录
可改的为
CMAKE_INSTALL_PREFIX是安装目录其中/usr/local为一般路径有时候不安在这,比如交叉编译opencv时
CMAKE_BUILD_TYPE 选择release还是debug版本,暂时看不太出来实际操作代码编写中的区别但是据说debug方便调试,release有算法优化适合发布
make
make install
详细版会讲我整个安装过程遇到的问题和各种参考链接,文本较多思路杂乱,也不是按照步骤写的,如果没遇到和我一样的问题推荐不要阅读。
默认已经完成
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/opencv/opencv-3.3.1/opencv_contrib-3.3.1/modules/ ..
没有cuda,python等各种东西只是单纯加了个扩展库OPENCV_EXTRA_MODULES_PATH= 这里应该填自己的contrib路径,没改导致出错修改后再编译(提示如果不需要扩展库直接命令sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local …,可以直接完成cmake成功自己试过了,但是我需要contrib库所以还要接着探索)
2.3 再次cmake会很慢再下载东西,而且大几率会有不少东西下载失败,但是cmake依然完成了 完成时最好几句话应该是
-- Install to: /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zjh/opencv-3.4/build
没有error
但是为了严谨还是看看下载失败的怎么弄回来
下载失败的各种东西就是
boostdesc_lbgm.i
boostdesc_binboost_256.i
boostdesc_binboost_128.i
之类的共11个文件
还有
face_landmark_model.dat
sudo apt-get install curl
创建执行如下脚本注意新建一个文件夹给他,很乱 手动下载缺少的文件
当然这样下载很慢我推荐直接用我下好的或者用别的下载器如迅雷下载
//方法来自https://blog.csdn.net/u011736771/article/details/85960300
// https://github.com/opencv/opencv_contrib/issues/1301
#!/bin/bash
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
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
/////原脚本长这样
#!/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
2.4按照上面操作会发现依然会帮你下载因为操作不对不是放到src文件夹下,根据原脚本发现是放在.cache目录下
同理之前的ippicv和之后同样下载失败的face_landmark_model也是手动下载后放到该目录下具体如下
face_landmark_model的data文件在windows下载后拖到linux用不了莫名其妙有个\(cp命令按tap补全文件名时可以看到自动补出一个\),而且同名文件放在一起可以不知道什么原因后来在linux重新下载后可以用了也没有\号在文件后面
将手动下载的文件改名为对应的文件名放在opencv主文件目录下的隐藏文件夹.cache即可(如我的在~/tools/opencv/opencv-3.4,输入ls命令在双击tab即可看到有.cache文件)
除了脚本处已知的11个文件外ippicv和face的命名如下
c0bd78adb4156bbf552c1dfe90599607-ippicv_2019_lnx_intel64_general_20180723.tgz (对没错不要解压)
7505c44ca4eb54b4ab1e4777cb96ac05-face_landmark_model.dat 哪里来的?在cmake完成后(即使一些东西下载失败了)在opencv-3.4文件下有隐藏文件夹.cache 这里是缓存,在里面有下载的几个东西的文件夹
1.data (你下载失败的face_landmark_model.dat放在这里)cd进去后就有了上面呢个文件名字了
2.xfeatures2d
3.ippicv
总结一下下载失败方法 先去build下 CMakeDownloadLog 查找自己下载失败的几个东西的下载链接,手动下载完后要么改CMakeList的路径要么去隐藏的.cache目录下把下载的放进去但是记住修改名字在拖进去,这和hash还是md5校验有关,下载失败后会残留正确文件名字在隐藏文件夹自己去复制粘贴
2.5以上应该大概cmake成功了
pkg-config --cflags --libs opencv
如果直接用5.中提供的例子则全命令是g++ DisplayImage.cpp -o Test `pkg-config --cflags --libs opencv`
可以运行了但是这个不能用交叉编译因为你原来编译opencv是在本机用的本地编译器生成了的是x86体系下的.so等文件,你还得用交叉编译工具重新编译opencv估计…