Opencv-4.5.2+opencv

Opencv-4.5.2+opencv,第1张

Opencv-4.5.2+opencv opencv-4.5.2+opencv_contrib-4.5.2+linux安装

个人使用的是opencv-4.5.2+opencv_contrib-4.5.2+linux安装,这里分享一下配置过程碰到的一些坑

下载源码

首先我们需要从官网或者Github上下载源码

# download opencv source code
git clone https://github.com/opencv/opencv
# download opecv contrib module
git clone https://github.com/opencv/opencv_contirb

将opencv_contrib文件夹移动到opencv路径下

cp -r opencv_contrib-4.5.2 opencv-4.5.2/
CMake配置

按照官方文档指示,输入以下命令

# create directory
mkdir build
cd build
# CMake configure
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.2 ..

等待结果,过程中会发现一些文件和模块下载失败,提示‘SSL connect error`

手动下载文件

我们在CMakeDownloadLog.txt中可以找到发生下载错误的地方,这里可以查看到哪些文件下载失败:

#do_unpack "ippicv_2020_lnx_intel64_20191018_general.tgz" "7421de0095c7a39162ae13a6098782f9" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ip    picv/ippicv_2020_lnx_intel64_20191018_general.tgz" "/home/ts/Disk_4T/test/opencv-4.5.2/build/3rdparty/ippicv"
check_md5 "/home/ts/Disk_4T/test/opencv-4.5.2/.cache/ippicv/7421de0095c7a39162ae13a6098782f9-ippicv_2020_lnx_intel64_20191018_general.tgz"
mismatch_md5 "/home/ts/Disk_4T/test/opencv-4.5.2/.cache/ippicv/7421de0095c7a39162ae13a6098782f9-ippicv_2020_lnx_intel64_20191018_general.tgz" "d41d8cd98f00b204e9800998ecf8427e"
delete "/home/ts/Disk_4T/test/opencv-4.5.2/.cache/ippicv/7421de0095c7a39162ae13a6098782f9-ippicv_2020_lnx_intel64_20191018_general.tgz"
cmake_download "/home/ts/Disk_4T/test/opencv-4.5.2/.cache/ippicv/7421de0095c7a39162ae13a6098782f9-ippicv_2020_lnx_intel64_20191018_general.tgz" "https://raw.githubusercontent.com/opencv/opencv_    3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_lnx_intel64_20191018_general.tgz"

这里可以看到尝试下载ippicv_2020_lnx_intel64_20191018_general.tgz这个文件失败了,可以使用

curl https://raw.githubusercontent.com/opencv/opencv_3rdparty/a56b6ac6f030c312b2dce17430eef13aed9af274/ippicv/ippicv_2020_lnx_intel64_20191018_general.tgz > /home/ts/Disk_4T/test/opencv-4.5.2/.cache/ippicv/7421de0095c7a39162ae13a6098782f9-ippicv_2020_lnx_intel64_20191018_general.tgz

下载完毕后再重新执行cmake就发现不会报错了,后续还有文件下载错误,都通过这样的步骤去检查和下载,直到没有报错误了就可以执行编译

编译
make -j7

等待编译完成,我的编译在最后编译gapi模块时报了语法的错误:

[ 93%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/render/ft_render.cpp.o
In file included from /home/ts/Disk_4T/opencv-4.5.2/modules/gapi/src/backends/ie/giebackend.hpp:11:0,
                 from /home/ts/Disk_4T/opencv-4.5.2/modules/gapi/src/backends/ie/giebackend.cpp:11:
/home/ts/Disk_4T/opencv-4.5.2/modules/gapi/include/opencv2/gapi/infer/ie.hpp: In constructor ‘cv::gapi::ie::Params::Params(const string&, const string&, const string&, const string&)’:
/home/ts/Disk_4T/opencv-4.5.2/modules/gapi/include/opencv2/gapi/infer/ie.hpp:206:124: error: converting to ‘std::unordered_map, std::pair >’ from initializer list would use explicit constructor ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const hasher&, const key_equal&, const allocator_type&) [with _Key = std::basic_string; _Tp = std::pair; _Hash = std::hash >; _Pred = std::equal_to >; _Alloc = std::allocator, std::pair > >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type = long unsigned int; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher = std::hash >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::key_equal = std::equal_to >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::allocator_type = std::allocator, std::pair > >]’
         : desc{ model, weights, device, {}, {}, {}, 0u, 0u, detail::ParamDesc::Kind::Load, true, {}, {}, {}, 1u}, m_tag(tag) {
                                                                                                                            ^
/home/ts/Disk_4T/opencv-4.5.2/modules/gapi/include/opencv2/gapi/infer/ie.hpp:206:124: error: converting to ‘std::unordered_set >’ from initializer list would use explicit constructor ‘std::unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(std::unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type, const hasher&, const key_equal&, const allocator_type&) [with _Value = std::basic_string; _Hash = std::hash >; _Pred = std::equal_to >; _Alloc = std::allocator >; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::size_type = long unsigned int; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::hasher = std::hash >; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::key_equal = std::equal_to >; std::unordered_set<_Value, _Hash, _Pred, _Alloc>::allocator_type = std::allocator >]’

这里是编译gapi模块出问题了,我们在配置时候确认把gapi模块编译给关闭掉

cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contriv-4.5.2 -DBUILD_opencv_gapi:BOOL=OFF -DBUILD_PERF_TESTS:BOOL=OFF ..

然后重新编译

make -j7

成功编译

安装
sudo make install

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4662039.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-06
下一篇 2022-11-06

发表评论

登录后才能评论

评论列表(0条)

保存