// 20201106更新opencv_contrib4.1.2(即nofree部分)离线安装
// 文中所提到的所有资源均可在https://download.csdn.net/download/cking0906/13092097下载。
一,opencv4.1.2安装
1,下载opencv4.1.2源码,压缩包大概有80多兆。
2,解压到指定目录。
3,打开终端并cd到opencv源码目录后,创建build目录。
4,cd到build目录后,执行cmake ..指令。
5,仔细查看终端输出,发现有如下问题:
5.1,
-- IPPICV: Download: ippicv_2019_lnx_intel64_general_20180723.tgz
-- Try 1 failed
--
=======================================================================
Couldn't download files from the Internet.
Please check the Internet access on this host.
=======================================================================
解决办法如下:
打开opencv-4.1.2/3rdparty/ippicv/ippicv.cmake文件,按照文件第47行指定的网址下载ippicv_2019_lnx_intel64_general_20180723.tgz文件(无法下载的可以自己搜索资源并下载),并修改第47行:
由
"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/"
改为
"file::///opt/tsinglee/opencv/download/ippicv/"
5.2,
-- ADE: Download: v0.1.1f.zip
-- Try 1 failed
--
=======================================================================
Couldn't download files from the Internet.
Please check the Internet access on this host.
=======================================================================
解决办法如下:
打开opencv-4.1.2/modules/gapi/cmake/DownloadADE.cmake文件,按照文件第15行指定的网址下载ade-0.1.1f.zip文件,并将其重命名为v0.1.1f.zip,并修改第15行:
由
"https://github.com/opencv/ade/archive/"
改为
"file::///opt/tsinglee/opencv/download/ade/"
6,重新执行cmake ..命令。
7,执行make命令。
8,执行sudo make install命令。
9,进入opencv-4.1.2/samples/cpp/example_cmake目录,用cmake方式成功编译,表示opencv已安装。
二,opencv_contrib4.1.2安装
1,下载opencv_contrib4.1.2源码,压缩包大概60多兆。
2,将其解压到上面安装过的opencv4.1.2同级目录。
3,再次进入build目录,执行cmake -D OPENCV_ENABLE_NONFREE=ON ..命令。
4,会出现如下错误:
4.1,
-- xfeatures2d/boostdesc: Download: boostdesc_bgm.i
-- Try 1 failed
--
=======================================================================
Couldn't download files from the Internet.
Please check the Internet access on this host.
=======================================================================
解决办法如下:
打开文件"/opt/tsinglee/opencv/opencv-4.1.2/modules/xfeatures2d/cmake/download_boostdesc.cmake"
由
"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${OPENCV_3RDPARTY_COMMIT}/"
改为
"file::///opt/tsinglee/opencv/download/3rdparty/boostdesc/"
4.2,
-- xfeatures2d/vgg: Download: vgg_generated_48.i
-- Try 1 failed
--
=======================================================================
Couldn't download files from the Internet.
Please check the Internet access on this host.
=======================================================================
解决办法如下:
打开文件"/opt/tsinglee/opencv/opencv-4.1.2/modules/xfeatures2d/cmake/download_vgg.cmake"
由
"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${OPENCV_3RDPARTY_COMMIT}/"
改为
"file::///opt/tsinglee/opencv/download/3rdparty/vgg/"
4.3,
-- data: Download: face_landmark_model.dat
-- Try 1 failed
--
=======================================================================
Couldn't download files from the Internet.
Please check the Internet access on this host.
=======================================================================
解决办法如下:
打开文件"/opt/tsinglee/opencv/opencv-4.1.2/modules/face/CMakeLists.txt"
由
"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${__commit_hash}/"
改为
"file::///opt/tsinglee/opencv/download/3rdparty/face/"
4.4,
fatal error: features2d/test/test_detectors_regression.impl.hpp: No such file or directory
compilation terminated.
modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/build.make:86: recipe for target 'modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/test/test_features2d.cpp.o' failed
解决办法1:
修改opencv的CMakeLists.txt,在第19行添加如下内容:
include_directories("modules")
即:
include(cmake/OpenCVMinDepVersions.cmake)
include_directories("modules")
解决办法2:
将opencv/modules/features2d目录复制并粘贴到build目录即可。
5,再次执行cmake -D OPENCV_ENABLE_NONFREE=ON ..命令,通过。
6,执行make命令。
7,执行sudo make install命令,安装成功。
注意:我的ubuntu环境之前已经下载安装过许多软件,因此在安装opencv时只有这两个下载提示。
在安装opencv之前,一定要先安装好其所需要的软件环境。类似于以下命令:
sudo apt-get installbuild-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