• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

【openCV踩坑日记】openCV3.X.X: nonfree模块的安装、调试和使用(SIFT的使用)

人工智能 iwande 1240次浏览 0个评论

opencv2/nonfree的安装 看了好多讲解怎么使用openCV-contrib的nonfree模块的内容,要么整不了,要么太麻烦了,今天花了一下午的时候调试通了,做个记录。(前提是你先安装了openCV_contrib,并且是Ubuntu系统) 要想用SIFT, 就需要#include <opencv2/nonfree/nonfree.hpp> 但是在编译的时候,会报错:  

<code class="prism language-cpp has-numbering">fatal error<span class="token operator">:</span> opencv2<span class="token operator">/</span>nonfree<span class="token punctuation">.</span>hpp<span class="token operator">:</span> No such file <span class="token operator">or</span> directory
</code>

  所以说这个时候,你就需要安装openCV的nonfree模块,输入以下内容,  

<code class="prism language-cpp has-numbering">sudo apt<span class="token operator">-</span>get update
sudo add<span class="token operator">-</span>apt<span class="token operator">-</span>repository <span class="token operator">--</span>yes ppa<span class="token operator">:</span>xqms<span class="token operator">/</span>opencv<span class="token operator">-</span>nonfree
sudo apt<span class="token operator">-</span>get update
sudo apt<span class="token operator">-</span>get install libopencv<span class="token operator">-</span>nonfree<span class="token operator">-</span>dev
</code>

  此时会报错:  

sudo apt-get install libopencv-nonfree-dev
正在读取软件包列表... 完成
正在分析软件包的依赖关系树       
正在读取状态信息... 完成       
有一些软件包无法被安装。如果您用的是 unstable 发行版,这也许是
因为系统无法达到您要求的状态造成的。该版本中可能会有一些您需要的软件
包尚未被创建或是它们已被从新到(Incoming)目录移出。
下列信息可能会对解决问题有所帮助:

下列软件包有未满足的依赖关系:
 libopencv-nonfree-dev : 依赖: libopencv-features2d-dev (= 2.4.9.1+dfsg-1.5ubuntu1xqms2~xenial1) 但是 2.4.9.1+dfsg-1.5ubuntu1.1 正要被安装
                         依赖: libopencv-nonfree2.4v5 (= 2.4.9.1+dfsg-1.5ubuntu1xqms2~xenial1) 但是它将不会被安装
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。

    这个时候,一般人都会卡住… 解决办法:下载依赖检查的功能强大的包管理工具 aptitude!  

<code class="prism language-cpp has-numbering">sudo apt<span class="token operator">-</span>get install aptitude
sudo aptitude install libopencv<span class="token operator">-</span>nonfree<span class="token operator">-</span>dev
</code>

 

第一个选no,之后的选yes!!!!

说多了都是泪,我当时第一个手太快选了yes,导致ros被删了,又得重新下载ros!可是在下载ros 的时候,即sudo rosdep init 的时候,又出现了Website may be down.的报错!又花了好长时间才解决! 这个办法是在Ubuntu上对缺少依赖的一种万能解法! 然后openCV的nonfree模块就安装成功了!!  

对nonfree.hpp的修改

但是,好不容易装完了,谁能想到,编译的时候又会报错:  

In file included from /usr/include/opencv2/nonfree/nonfree.hpp:46:0,
                 from /home/XXX/SLAM/XXX/SLAM/feature_tester/test_on_image/TestOnImage/feature_tester.cpp:8:
/usr/include/opencv2/nonfree/features2d.hpp:73:21: error: ‘vector’ has not been declared
                     vector<KeyPoint>& keypoints) const;
                     ^
/usr/include/opencv2/nonfree/features2d.hpp:73:27: error: expected ‘,’ or ‘...’ before ‘<’ token
                     vector<KeyPoint>& keypoints) const;
                           ^
/usr/include/opencv2/nonfree/features2d.hpp:77:21: error: ‘vector’ has not been declared
                     vector<KeyPoint>& keypoints,
                     ^
/usr/include/opencv2/nonfree/features2d.hpp:77:27: error: expected ‘,’ or ‘...’ before ‘<’ token
                     vector<KeyPoint>& keypoints,
                           ^
/usr/include/opencv2/nonfree/features2d.hpp:76:10: error: ‘void cv::SIFT::operator()(cv::InputArray, cv::InputArray, int) const’ cannot be overloaded
     void operator()(InputArray img, InputArray mask,
          ^
/usr/include/opencv2/nonfree/features2d.hpp:72:10: error: with ‘void cv::SIFT::operator()(cv::InputArray, cv::InputArray, int) const’
     void operator()(InputArray img, InputArray mask,
          ^
/usr/include/opencv2/nonfree/features2d.hpp:81:5: error: ‘AlgorithmInfo’ does not name a type
     AlgorithmInfo* info() const;
     ^
/usr/include/opencv2/nonfree/features2d.hpp:83:49: error: ‘vector’ has not been declared
     void buildGaussianPyramid( const Mat& base, vector<Mat>& pyr, int nOctaves 
                                                 ^
/usr/include/opencv2/nonfree/features2d.hpp:83:55: error: expected ‘,’ or ‘...’ before ‘<’ token
     void buildGaussianPyramid( const Mat& base, vector<Mat>& pyr, int nOctaves 
                                                       ^
/usr/include/opencv2/nonfree/features2d.hpp:84:33: error: ‘vector’ does not name a type
     void buildDoGPyramid( const vector<Mat>& pyr, vector<Mat>& dogpyr ) const;
                                 ^
/usr/include/opencv2/nonfree/features2d.hpp:84:39: error: expected ‘,’ or ‘...’ before ‘<’ token
     void buildDoGPyramid( const vector<Mat>& pyr, vector<Mat>& dogpyr ) const;
                                       ^
/usr/include/opencv2/nonfree/features2d.hpp:85:39: error: ‘vector’ does not name a type
     void findScaleSpaceExtrema( const vector<Mat>& gauss_pyr, const vector<Mat>
                                       ^
/usr/include/opencv2/nonfree/features2d.hpp:85:45: error: expected ‘,’ or ‘...’ before ‘<’ token
     void findScaleSpaceExtrema( const vector<Mat>& gauss_pyr, const vector<Mat>
                                             ^
/usr/include/opencv2/nonfree/features2d.hpp:89:40: error: ‘vector’ has not been declared
     void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& 
                                        ^
/usr/include/opencv2/nonfree/features2d.hpp:89:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& 
                                              ^
/usr/include/opencv2/nonfree/features2d.hpp:90:41: error: ‘vector’ has not been declared
     void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descr
                                         ^
/usr/include/opencv2/nonfree/features2d.hpp:90:47: error: expected ‘,’ or ‘...’ before ‘<’ token
     void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descr
                                               ^
/usr/include/opencv2/nonfree/features2d.hpp:125:28: error: ‘vector’ has not been declared
                     CV_OUT vector<KeyPoint>& keypoints) const;
                            ^
/usr/include/opencv2/nonfree/features2d.hpp:125:34: error: expected ‘,’ or ‘...’ before ‘<’ token
                     CV_OUT vector<KeyPoint>& keypoints) const;
                                  ^
In file included from /usr/include/opencv2/nonfree/nonfree.hpp:46:0,
                 from /home/huruiqi/SLAM/orbbec/SLAM/feature_tester/test_on_image/TestOnImage/feature_tester.cpp:8:
/usr/include/opencv2/nonfree/features2d.hpp:128:28: error: ‘vector’ has not been declared
                     CV_OUT vector<KeyPoint>& keypoints,
                            ^
/usr/include/opencv2/nonfree/features2d.hpp:128:34: error: expected ‘,’ or ‘...’ before ‘<’ token
                     CV_OUT vector<KeyPoint>& keypoints,
                                  ^
/usr/include/opencv2/nonfree/features2d.hpp:127:10: error: ‘void cv::SURF::operator()(cv::InputArray, cv::InputArray, int) const’ cannot be overloaded
     void operator()(InputArray img, InputArray mask,
          ^
In file included from /usr/include/opencv2/nonfree/nonfree.hpp:46:0,
                 from /home/huruiqi/SLAM/orbbec/SLAM/feature_tester/test_on_image/TestOnImage/feature_tester.cpp:8:
/usr/include/opencv2/nonfree/features2d.hpp:124:10: error: with ‘void cv::SURF::operator()(cv::InputArray, cv::InputArray, int) const’
     void operator()(InputArray img, InputArray mask,
          ^
In file included from /usr/include/opencv2/nonfree/nonfree.hpp:46:0,
                 from /home/huruiqi/SLAM/orbbec/SLAM/feature_tester/test_on_image/TestOnImage/feature_tester.cpp:8:
/usr/include/opencv2/nonfree/features2d.hpp:132:5: error: ‘AlgorithmInfo’ does not name a type
     AlgorithmInfo* info() const;
     ^
/usr/include/opencv2/nonfree/features2d.hpp:142:40: error: ‘vector’ has not been declared
     void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& 
                                        ^
/usr/include/opencv2/nonfree/features2d.hpp:142:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& 
                                              ^
/usr/include/opencv2/nonfree/features2d.hpp:143:41: error: ‘vector’ has not been declared
     void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descr
                                         ^
/usr/include/opencv2/nonfree/features2d.hpp:143:47: error: expected ‘,’ or ‘...’ before ‘<’ token
     void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descr

  然后,根据路径/usr/include/opencv2/nonfree/features2d.hpp找到这个文件,首先  

<code class="prism language-cpp has-numbering">sudo chmod <span class="token number">777</span> features2d<span class="token punctuation">.</span>cpp
</code>

  然后打开,加上以下内容:  

<code class="prism language-cpp has-numbering"><span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string"><vector></span></span>
<span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string"><opencv2/core/core.hpp></span></span>
<span class="token keyword">using</span> <span class="token keyword">namespace</span> std<span class="token punctuation">;</span>
</code>

  在namespace cv里加上声明:  

<code class="prism language-cpp has-numbering"><span class="token keyword">class</span> <span class="token class-name">AlgorithmInfo</span><span class="token punctuation">;</span>
</code>

  保存,终于可以用SIFT了!! 原图:  
【openCV踩坑日记】openCV3.X.X: nonfree模块的安装、调试和使用(SIFT的使用)   SIFT角点:  
【openCV踩坑日记】openCV3.X.X: nonfree模块的安装、调试和使用(SIFT的使用)    


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明【openCV踩坑日记】openCV3.X.X: nonfree模块的安装、调试和使用(SIFT的使用)
喜欢 (0)

您必须 登录 才能发表评论!

加载中……