在Ubuntu

时间:2015-05-05 21:00:51

标签: c++ linux eclipse opencv makefile

我一直在另一台计算机上处​​理this tutorial现在,在回到家后,我似乎无法再运行代码了。

我一直遇到类似以下错误的错误:

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添加nonfree和contrib模块

  • 使用g ++ - 4.8而不是g ++作为编译器

  • 检查并添加了基本上所有OpenCV库中的新包含/链接

  • 哭了一点

这是Eclipse创建和使用的makefile:

  #      

自动生成的文件。不要编辑!

     #      

-include ../ makefile.init

     

RM:= rm

     

参与构建的所有源都在此处定义

     

-include sources.mk   -include image-processor / src / subdir.mk   -include image-processor / references / subdir.mk   -include subdir.mk   -include objects.mk

     

ifneq($(MAKECMDGOALS),clean)ifneq($(strip $(C ++ _ DEPS)),)   -include $(C ++ _ DEPS)endif ifneq($(strip $(C_DEPS)),)   -include $(C_DEPS)endif ifneq($(strip $(CC_DEPS)),)   -include $(CC_DEPS)endif ifneq($(strip $(CPP_DEPS)),)   -include $(CPP_DEPS)endif ifneq($(strip $(CXX_DEPS)),)   -include $(CXX_DEPS)endif ifneq($(strip $(C_UPPER_DEPS)),)   -include $(C_UPPER_DEPS)endif endif

     

-include ../ makefile.defs

     

将这些工具调用的输入和输出添加到构建变量

     

所有目标全部:shared-robovision

     

工具调用shared-robovision:$(OBJS)$(USER_OBJS)@echo'构建目标:$ @'@ echo'调用:GCC C ++链接器'g ++

     

-L / usr / lib / i386-linux-gnu / -L / usr / local / include / opencv -L / usr / local / include / opencv2 -o“shared-robovision”$(OBJS)$(USER_OBJS )$(LIBS)@echo'完成建筑目标:$ @'@ echo''

     

其他目标清理: - $(RM)$(OBJS)$(C ++ _ DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS)

     

shared-robovision - @ echo''

     

.PHONY:所有干净的家属.SECONDARY:

     

-include ../ makefile.targets

以下是我收录的图书馆:

  

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_imgproc

修改

我的标题:

#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;

1 个答案:

答案 0 :(得分:2)

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

OrderLocation = 4

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

-lopencv_core -lopencv_highgui -lopencv_features2d -lopencv_nonfree -lopencv_flann -lopencv_calib3d

现在你需要告诉链接器lib文件在哪里,因此

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

调用-L/.../opencv-2.4.10/release/lib编译器

g++

我正在使用ubuntu和opencv 2.4.10。样品运行完美。