ubuntu安装opencv_contrib扩展库,附踩坑+测试

这篇具有很好参考价值的文章主要介绍了ubuntu安装opencv_contrib扩展库,附踩坑+测试。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

博主昨晚需要用到OpenCV的SURF接口,但是发现无法调用,因为没有头文件。于是查阅了下资料,发现这些库已经被美国买下专利,成为付费库,都在opencv_contrib中。如果你已经安装了OpenCV,或者还没有安装OpenCV,都可以跟随本教程安装好opencv_contrib。

1、安装OpenCV

如果还没有安装过OpenCV,可以先看下:Ubuntu安装OpenCV3.4.5(两种方法&&图文详解),安装好之后可以按照下面步骤进行。

ubuntu安装opencv_contrib扩展库,附踩坑+测试

2、下载opencv_contrib

下载opencv_contrib,在Tags里找到自己对应的版本进行下载。然后将opencv_contrib解压到opencv目录下。

ubuntu安装opencv_contrib扩展库,附踩坑+测试

3、cmake分析

启动终端,cd到build目录,输入下面命令,Path后是你的modules的目录。

cmake -D CMAKE_BUILD_TYPE=RELEASE -D OPENCV_EXTRA_MODULES_PATH=~/Software/opencv-3.4.5/opencv_contrib-3.4.5/modules ..

应该会出现下面的未安装的问题:

-- xfeatures2d/vgg: Download: vgg_generated_64.i
CMake Warning at cmake/OpenCVDownload.cmake:193 (message):
  xfeatures2d/vgg: Download failed: 28;"Timeout was reached"

  For details please refer to the download log file:

  /home/dzh/Software/opencv-3.4.5/build/CMakeDownloadLog.txt

Call Stack (most recent call first):
  opencv_contrib-3.4.5/modules/xfeatures2d/cmake/download_vgg.cmake:16 (ocv_download)
  opencv_contrib-3.4.5/modules/xfeatures2d/CMakeLists.txt:9 (download_vgg_descriptors)


-- xfeatures2d/vgg: Download: vgg_generated_80.i
-- 
=======================================================================
  Couldn't connect to server from the Internet.
  Perhaps direct connections are not allowed in the current network.
  To use proxy please check/specify these environment variables:
  - http_proxy/https_proxy
  - and/or HTTP_PROXY/HTTPS_PROXY
=======================================================================

CMake Warning at cmake/OpenCVDownload.cmake:193 (message):
  xfeatures2d/vgg: Download failed: 7;"Couldn't connect to server"

  For details please refer to the download log file:

  /home/dzh/Software/opencv-3.4.5/build/CMakeDownloadLog.txt

Call Stack (most recent call first):
  opencv_contrib-3.4.5/modules/xfeatures2d/cmake/download_vgg.cmake:16 (ocv_download)
  opencv_contrib-3.4.5/modules/xfeatures2d/CMakeLists.txt:9 (download_vgg_descriptors)


-- data: Download: face_landmark_model.dat
-- 
=======================================================================
  Couldn't connect to server from the Internet.
  Perhaps direct connections are not allowed in the current network.
  To use proxy please check/specify these environment variables:
  - http_proxy/https_proxy
  - and/or HTTP_PROXY/HTTPS_PROXY
=======================================================================

CMake Warning at cmake/OpenCVDownload.cmake:193 (message):
  data: Download failed: 7;"Couldn't connect to server"

  For details please refer to the download log file:

  /home/dzh/Software/opencv-3.4.5/build/CMakeDownloadLog.txt

Call Stack (most recent call first):
  opencv_contrib-3.4.5/modules/face/CMakeLists.txt:13 (ocv_download)


CMake Warning at opencv_contrib-3.4.5/modules/face/CMakeLists.txt:26 (message):
  Face: Can't get model file for face alignment.


-- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
-- Found installed version of gflags: /usr/lib/x86_64-linux-gnu/cmake/gflags
-- Detected gflags version: 2.2.1
-- Found installed version of Eigen: /usr/local/lib/cmake/eigen3
-- Found required Ceres dependency: Eigen version 3.2.92 in /usr/local/include/eigen3
-- Found required Ceres dependency: glog
-- Found installed version of gflags: /usr/lib/x86_64-linux-gnu/cmake/gflags
-- Detected gflags version: 2.2.1
-- Found required Ceres dependency: gflags
-- Found Ceres version: 1.14.0 installed in: /usr/local with components: [EigenSparse, SparseLinearAlgebraLibrary, LAPACK, SuiteSparse, CXSparse, SchurSpecializations, OpenMP, Multithreading]
-- Checking SFM deps... TRUE

其实是因为网络连接问题,无法连接到下载地址,所以下载失败。网上的所有教程总结下来就是:1、更换热点,多连几次;2、从网上下载好文件到本地;3、修改下载地址,

这里我采用科学上网,依次到github上下载文件到本地,将下载好的boostdesc_bgm.i系列和vgg_generated_48.i系列放到opencv-3.4.5/opencv_contrib-3.4.5/modules/xfeatures2d/src/目录下。将下载好的face_landmark_model.dat放到opencv-3.4.5/opencv_contrib-3.4.5/modules/face/src/

ubuntu安装opencv_contrib扩展库,附踩坑+测试
再次输入cmake命令进行分析,还会报上面文件的错误,但是不需要管它,因为需要的文件我们已经有了。

4、make编译

输入sudo make -j4进行编译,-j4表示采用4线程运行。

Error 1
In file included from /home/dzh/Software/opencv-3.4.5/modules/stitching/include/opencv2/stitching.hpp:49:0,
                 from /home/dzh/Software/opencv-3.4.5/modules/stitching/src/precomp.hpp:59,
                 from /home/dzh/Software/opencv-3.4.5/build/modules/stitching/opencv_stitching_pch_dephelp.cxx:1:
/home/dzh/Software/opencv-3.4.5/modules/stitching/include/opencv2/stitching/detail/matchers.hpp:52:12: fatal error: opencv2/xfeatures2d/cuda.hpp: 没有那个文件或目录
 #  include "opencv2/xfeatures2d/cuda.hpp"
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/build.make:62: recipe for target 'modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/opencv_stitching_pch_dephelp.cxx.o' failed
make[2]: *** [modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/opencv_stitching_pch_dephelp.cxx.o] Error 1
CMakeFiles/Makefile2:15804: recipe for target 'modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/all' failed
make[1]: *** [modules/stitching/CMakeFiles/opencv_stitching_pch_dephelp.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....

相信一定会出现上面的ERROR,原因是include的cuda.hpp头文件路径找不到,需要改为绝对路径。打开它提示的文件matchers.hpp,然后找到你的cuda.hpp目录,如下所示。

ubuntu安装opencv_contrib扩展库,附踩坑+测试复制你的路径,然后替换掉include "opencv2/xfeatures2d/cuda.hpp",比如我的路径:/home/dzh/Software/opencv-3.4.5/opencv_contrib-3.4.5/modules/xfeatures2d/include/opencv2/xfeatures2d/cuda.hpp

Error 2
In file included from /home/dzh/Software/opencv-3.4.5/build/modules/stitching/opencv_stitching_pch_dephelp.cxx:1:0:
/home/dzh/Software/opencv-3.4.5/modules/stitching/src/precomp.hpp:91:12: fatal error: opencv2/xfeatures2d/cuda.hpp: 没有那个文件或目录
 #  include "opencv2/xfeatures2d/cuda.hpp"
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

有了Error1的经验,根据报错信息找到错误文件的地方,将路径改为上面的绝对路径。

Error 3
[ 90%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/matchers.cpp.o
/home/dzh/Software/opencv-3.4.5/modules/stitching/src/matchers.cpp:52:10: fatal error: opencv2/xfeatures2d.hpp: 没有那个文件或目录
 #include "opencv2/xfeatures2d.hpp"
          ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
modules/stitching/CMakeFiles/opencv_stitching.dir/build.make:164: recipe for target 'modules/stitching/CMakeFiles/opencv_stitching.dir/src/matchers.cpp.o' failed
make[2]: *** [modules/stitching/CMakeFiles/opencv_stitching.dir/src/matchers.cpp.o] Error 1
CMakeFiles/Makefile2:15854: recipe for target 'modules/stitching/CMakeFiles/opencv_stitching.dir/all' failed
make[1]: *** [modules/stitching/CMakeFiles/opencv_stitching.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[ 90%] Building CXX object modules/sfm/CMakeFiles/opencv_sfm.dir/src/simple_pipeline.cpp.o
/home/dzh/Software/opencv-3.4.5/opencv_contrib-3.4.5/modules/sfm/src/simple_pipeline.cpp:44:10: fatal error: opencv2/xfeatures2d.hpp: 没有那个文件或目录
 #include <opencv2/xfeatures2d.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
modules/sfm/CMakeFiles/opencv_sfm.dir/build.make:230: recipe for target 'modules/sfm/CMakeFiles/opencv_sfm.dir/src/simple_pipeline.cpp.o' failed
make[2]: *** [modules/sfm/CMakeFiles/opencv_sfm.dir/src/simple_pipeline.cpp.o] Error 1
make[2]: *** 正在等待未完成的任务....

报错显示找不到xfeatures2d.hpp,同理,还是找到报错的地方,然后将路径改为绝对路径:

/home/dzh/Software/opencv-3.4.5/opencv_contrib-3.4.5/modules/xfeatures2d/include/opencv2/xfeatures2d.hpp
Success

经历了种种错误,最终make成功!正应了古话:世上无难事,只怕有心人。

ubuntu安装opencv_contrib扩展库,附踩坑+测试

5、make install安装

安装的过程是非常快的,大概15s就安装好了。

sudo make install

ubuntu安装opencv_contrib扩展库,附踩坑+测试

6、测试安装

#include <QApplication>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/xfeatures2d/nonfree.hpp"
#include "opencv2/xfeatures2d.hpp"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    cv::Mat image = cv::imread("/home/dzh/QtOpenCV/image.png", 0); //以灰度图像读取
    vector<cv::KeyPoint> keypoints;//特征点数组
//    cv::FAST(image, keypoints, 40, true); //Fast特征点
//    cv::drawKeypoints(image, keypoints, image, cv::Scalar(255 ,255, 255), cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);
    cv::Ptr<cv::xfeatures2d::SURF> detector = cv::xfeatures2d::SURF::create(2500.);//初始化检测器对象
    detector->detect(image, keypoints);//检测SURF特征点
    cv::drawKeypoints(image, keypoints, image, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);//绘制特征点
    cv::imshow("image", image);
    cv::waitKey(0);
    return a.exec();
}

ubuntu安装opencv_contrib扩展库,附踩坑+测试文章来源地址https://www.toymoban.com/news/detail-411949.html

到了这里,关于ubuntu安装opencv_contrib扩展库,附踩坑+测试的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Ubuntu18.04,opencv-4.3.0和opencv_contrib-4.3.0安装(填坑)

    如果觉得本篇文章对您的学习起到帮助作用,请 点赞 + 关注 + 评论 ,留下您的足迹💪💪💪 本文主要Ubuntu18.04安装opencv-4.3.0和opencv_contrib-4.3.0,坑巨多,因此记录以备日后查看,同时,如果能够帮助到更多人,也不胜荣幸。 本文所使用安装包,百度网盘: 链接:https://pan.

    2024年02月12日
    浏览(78)
  • Ubuntu20.04安装OpenCV4.5.5和OpenCV_Contrib4.5.5

    进入到最开始自己的安装opencv的build目录 然后返回到初始目录,删除掉build目录 删除opencv其他的相关文件 前四行命令中的opencv2,有些有可能自己命名了opencv4,在相关目录下删除掉跟opencv相关的文件夹就可以。 检查是否完全删除: 源程序下载地址 https://github.com/opencv 下载好

    2024年02月03日
    浏览(68)
  • ubuntu20.0.4安装opencv4.2.0和opencv_contrib-4.2.0并支持CUDA,Geforce RTX 3060显卡,算力8.6

    参考:Ubuntu系统---配置OpenCV  1、首先更新 apt-get,在安装前最好先更新一下系统,不然有可能会安装失败。在终端输入: 2、接着安装官方给的opencv依赖包,在终端输入: OpenCV3.4.x版本+Opencv_contrib+Ubuntu16.04安装记录_YuYunTan的博客-CSDN博客 安装前的必备包   这些安装不算十分完

    2024年02月01日
    浏览(61)
  • 如何安装 OpenCV 和 OpenCV_contrib

    首先,从opencv官网下载opencv3.4.0以及opencv_contrib压缩包: https://opencv.org/releases/ 在页面下找到3.4.0版本并下载Sources压缩包 opencv_contrib下载网址 https://github.com/opencv/opencv_contrib

    2024年02月16日
    浏览(50)
  • Opencv+Visual studio +cmake配置+Opencv_contrib库安装(详细级)

    目的:安装Opencv, Opencv_contrib库,配置Visual studio,用cmake编译配置 这里我选择下载Visual studio2022版本的:官网下载 选择社区版Community下载(社区版Community是对个人免费的,一共有三个版本),这里下载的是.exe 可执行文件 ,比较小,大约1.57M 启动安装 ,配置工作负荷(按照自

    2024年02月15日
    浏览(64)
  • OpenCV_contrib配置教程(详细版)

    个人笔记: 操作系统:Windows 10或Windows 11 软件:Visual Studio 2017、OpenCV4.5.1、OpenCV_contrib4.5.1扩展库、Cmake3.19.3. 个人用到是vs2017,这里vs版本也可以用2015,2019,等,自己尝试即可。 注意:OpenCV基础库和contrib扩展库的版本一定要一致!!! 1:OpenCV4.5.1、OpenCV_contrib4.5.1扩展库下载

    2024年02月09日
    浏览(52)
  • RK3588移植opencv(包含opencv_contrib)过程

    后面给大家准备了我自己编译好的(百度云链接),如果有用,麻烦点个赞!!! PC端:Ubuntu 16.04  opencv 版本: 3.4.13 编译器:aarch64-linux-gnu 工具:cmake opencv-3.4.13 http://链接:https://pan.baidu.com/s/1YBohe41YuOhBZ2iCIupmLA 提取码:0012 --来自百度网盘超级会员V4的分享 opencv_contrib-3.4.

    2024年02月16日
    浏览(45)
  • CMAKE编译 opencv、opencv_contrib出现ADE无法下载解决方案

    问题: CMake Error at xxxx/DownlodeADE.cmake:23(add_library): 解决方案:你的opencv的安装路径下,(我的路径就是opencv4.5.4/modules/gapi/cmke/ )找到如下图片,打开DownloadADE.cmake文件 文件中有github网址,需要去文件中提供的网址下载文件,我的opencv版本是4.5.4,有需要可以滴滴。 第一行是你

    2024年02月22日
    浏览(60)
  • [opencv][windows]cmake opencv opencv_contrib所需的缓存文件下载

    这个是windows上源码编译opencv+opencv-contrib时候cmake时候缓存文件,只需要将压缩文件夹解压到源码目录下面,cmake-gui上configure时候就不会报错,注意解压后文件夹名字是.cache,文件夹名字不能改变,比如opencv/.cache,有的人解压后成opencv/.cache/.cache是错误的,请仔细检查文件夹名字

    2024年02月19日
    浏览(55)
  • cmake 编译opencv_contrib源码 生成jar包解决org.opencv.face.LBPHFaceRecognizer不存在问题。

    我这里有道的问题是用openCV做人脸识别的时候我用的是java, 实际写代码的时候 发现下载下来的jar包里面没有org.opencv.face.LBPHFaceRecognizer;后面百度才看到 LBPHFaceRecognizer 文件在opencv_contrib里面,但是导出百度都找不到已经编译好的jar包,就只能自己编译了。 给个百度网盘的下

    2024年02月19日
    浏览(58)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包