首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >OpenCV在Ubuntu上使用非空闲库(用于Surf描述符)的编译错误

OpenCV在Ubuntu上使用非空闲库(用于Surf描述符)的编译错误
EN

Stack Overflow用户
提问于 2015-05-05 21:00:51
回答 1查看 5.2K关注 0票数 2

我一直在另一台电脑上做本教程,现在,回到家后,我似乎不能再运行代码了。

我不断收到类似于以下错误的错误:

代码语言:javascript
运行
复制
g++-4.8 -I/usr/local/include/opencv -I/usr/lib/i386-linux-gnu/ -I/usr/local/include/opencv2 -O2 -g -Wall -c -fmessage-length=0 -MMD -MP -MF"image-processor/references/homography.d" -MT"image-processor/references/homography.d" -o "image-processor/references/homography.o" "../image-processor/references/homography.cpp"
In file included from /usr/include/opencv2/nonfree/nonfree.hpp:46:0,
                 from ../image-processor/references/homography.cpp:10:
/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 ) const;
                                                 ^
/usr/include/opencv2/nonfree/features2d.hpp:83:55: error: expected ‘,’ or ‘...’ before ‘<’ token
     void buildGaussianPyramid( const Mat& base, vector<Mat>& pyr, int nOctaves ) const;
                                                       ^
/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>& dog_pyr,
                                       ^
/usr/include/opencv2/nonfree/features2d.hpp:85:45: error: expected ‘,’ or ‘...’ before ‘<’ token
     void findScaleSpaceExtrema( const vector<Mat>& gauss_pyr, const vector<Mat>& dog_pyr,
                                             ^
/usr/include/opencv2/nonfree/features2d.hpp:89:40: error: ‘vector’ has not been declared
     void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
                                        ^
/usr/include/opencv2/nonfree/features2d.hpp:89:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
                                              ^
/usr/include/opencv2/nonfree/features2d.hpp:90:41: error: ‘vector’ has not been declared
     void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
                                         ^
/usr/include/opencv2/nonfree/features2d.hpp:90:47: error: expected ‘,’ or ‘...’ before ‘<’ token
     void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
                                               ^
/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 ../image-processor/references/homography.cpp:10:
/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 ../image-processor/references/homography.cpp:10:
/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 ../image-processor/references/homography.cpp:10:
/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& mask=Mat() ) const;
                                        ^
/usr/include/opencv2/nonfree/features2d.hpp:142:46: error: expected ‘,’ or ‘...’ before ‘<’ token
     void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
                                              ^
/usr/include/opencv2/nonfree/features2d.hpp:143:41: error: ‘vector’ has not been declared
     void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
                                         ^
/usr/include/opencv2/nonfree/features2d.hpp:143:47: error: expected ‘,’ or ‘...’ before ‘<’ token
     void computeImpl( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
                                               ^
../image-processor/references/homography.cpp: In function ‘int main(int, char**)’:
../image-processor/references/homography.cpp:83:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for( int i = 0; i < good_matches.size(); i++ )
                                         ^
../image-processor/references/homography.cpp:108:24: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
   char* image_window = "Window";
                        ^
make: *** [image-processor/references/homography.o] Error 1

**** Build Finished ****

我做了很多研究,做了以下工作:

  • 重新编译的OpenCV添加了非自由模块和控制模块
  • 用g++-4.8代替g++作为编译器
  • 检查并添加了OpenCV中基本上所有库的新包含/链接
  • 叫了一会

下面是Eclipse创建和使用的makefile:

自动生成的文件。不要编辑! # -include ../makefile.init RM := rm 参与构建的所有源都在这里定义。 -include sources.mk -include图像处理器/src/ subdir.mk -include图像处理器/references/subdir.mk -include subdir.mk -include objects.mk ifneq ($(MAKECMDGOALS),clean) ifneq ( $(C++_DEPS)),-include $(C++_DEPS) endif ifneq ( $(C_DEPS)),-include $(C_DEPS) endif ifneq ($(剥$(CC_DEPS)),-include $(CC_DEPS) endif ifneq ($(strip $(CPP_DEPS)),) -include $(CPP_DEPS) endif ifneq ($(剥$(CXX_DEPS),) -include $(CXX_DEPS) endif ifneq ($(strip $(C_UPPER_DEPS)),-include $(C_UPPER_DEPS) endif endif -include ./makefile.defs 将这些工具调用的输入和输出添加到构建变量中。 所有目标:共享机器人视觉 工具调用共享-机器人视觉:$(OBJS) $(USER_OBJS) @echo“构建目标:$@‘@echo’调用: GCC C++ Linker‘g++ -L/usr/lib/i 386-linux-gnu/ -L/usr/local/include/opencv 2 -o 其他目标清除:$(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) -$(RM) 共享-机器人视觉-@echo‘’ .PHONY:所有干净的受抚养人.SECONDARY: -include ./makefile.Target

以下是我所包括的图书馆:

USER_OBJS := LIBS := -lopencv_core -lopencv_xfeatures2d -lopencv_nonfree -lopencv_flann -lopencv_legacy -lopencv_contrib -lopencv_objdetect -lopencv_calib3d -lopencv_features2d -lopencv_imgcodecs -lopencv_imgproc -lopencv_video -lopencv_ml -lopencv_ts -lopencv_videostab -lopencv_highgui -lopencv_highgui-lopencv_ts-lopencv_videostab-lopencv_ml-lopencv_ts-lopencv_videostab-lopencv_videostab-lopencv_highgui -lopencv_imgproc

编辑:

我的标题:

代码语言:javascript
运行
复制
#include <stdio.h>
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/opencv_modules.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/nonfree/features2d.hpp>

using namespace cv;
using namespace std;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-05 22:29:45

要运行该示例,您需要以下库

代码语言:javascript
运行
复制
-lopencv_core 
-lopencv_highgui 
-lopencv_features2d 
-lopencv_nonfree
-lopencv_flann 
-lopencv_calib3d

因此,现在您需要告诉编译器头文件在哪里。

-I/.../opencv-2.4.10/install/include

因此,现在您需要告诉链接器库文件在哪里。

-L/.../opencv-2.4.10/release/lib

调用g++编译器

代码语言:javascript
运行
复制
g++ main.cpp -o test -I/.../opencv-2.4.10/install/include  -L/.../opencv-2.4.10/release/lib -lopencv_core -lopencv_highgui -lopencv_features2d -lopencv_nonfree -lopencv_flann -lopencv_calib3d

我使用的是ubuntu和opencv 2.4.10。样品运行得很好。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30063183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档