赞
踩
全过程参考
https://blog.csdn.net/qq_57160761/article/details/126982393
https://blog.csdn.net/gentleman1358/article/details/126955032
官网下载sources的zip包,速度很慢建议挂vpn。
很多帖子都说一定要安装3.4.0,我就没有冒险安装最新发布的版本
官网地址:https://opencv.org/releases/page/4/
可以用wegt方法,但我的失败了,还是推荐官网下载吧。放下wegt方法下载的命令:
wget https://github.com/opencv/opencv/archive/3.4.0.zip
unzip opencv-3.4.0.zip
jar xvf opencv-3.4.0.zip
cd opencv 3.4.0
(1)安装依赖库和cmake
sudo apt-get install update
apt-get install cmake
apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
(2)此时opencv-3.4.0文件夹里是没有build这个文件的,这需要我们自己生成, 然后进入build文件夹:
mkdir build && cd build
(3)cmake
cmake .. -DWITH_GTK_2_X=ON -DCMAKE_INSTALL_PREFIX=/usr/local
或者也可以
cmake ..
这一步我的报错非常之多,下面都贴出来。如果你没有报错说明你人品极好,可以跳过。
sudo apt install gcc
THEN,发生了一件怪事:安完说没安,黑人问号???
解决办法:
sudo apt install --reinstall gcc
为了以防万一我建议你们g++也reinstall一下吧
sudo apt install --reinstall g++
报错2:找不到CMakeLists.txt
CMakeLists.txt文件不在你指定的路径里,进入它所在的路径再cmake命令就可以了。
报错3:CMakeLists.txt重复
因为上一步cmake实在opencv的根目录进行的,错误生成了CMakeCache.txt文件,需要删掉他:(!!!删除的是opencv-3.4.0目录下的!!!),之后进入build文件夹再cmake命令
rm CMakeCache.txt
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler sudo apt-get install –no-install-recommends libboost-all-dev sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-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 --assume-yes libopencv-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip sudo apt-get install ffmpeg libopencv-dev libgtk-3-dev python-numpy python3-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libv4l-dev libtbb-dev qtbase5-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev
中间如果某个包没有成功,暂时不用理会。cmake一下,果然我又报错了,和之前一样的错误。暂时排除依赖的问题,可能是ippicv的问题(ippicv是个并行计算库),把他off掉
sudo cmake .. -DCMAKE_BUILD_TYPE=Release -DCUDA_nppi_LIBRARY=true -DWITH_CUDA=OFF -DBUILD_TIFF=ON
然后成功了
make
敲完回车你的屏幕就绿了一片,等就完了。
sudo make install
sudo gedit /etc/ld.so.conf.d/opencv.conf
打开是个空白文档,添加 /usr/local/lib
如下图:
sudo ldconfig
sudo gedit /etc/bash.bashrc
在文件末尾加入:(有WARNING异常的话往下看)
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
如下图:
编辑之后会出现如下WARNING,忽略就行了。不安心的话,打开刚编辑的文件看下是不是已经更新了就行。
sudo updatedb
cd /home/mat/opencv-3.4.0/samples/cpp/example_cmake
cmake .
make
./opencv_example
然后会出现Hello OpenCV,你就成功了! 我也成功了,终于成功了!!!
配置参考:
https://blog.csdn.net/lumingha/article/details/88819631
https://www.linuxidc.com/Linux/2019-05/158462.htm
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。