OpenCV-未定义的引用:SurfFeatureDetector和BruteForceMatcher 我正在制作一个C++程序,它使用2幅图像来检测冲浪特征,用BruttFixCaltCter计算匹配,并绘制它。

OpenCV-未定义的引用:SurfFeatureDetector和BruteForceMatcher 我正在制作一个C++程序,它使用2幅图像来检测冲浪特征,用BruttFixCaltCter计算匹配,并绘制它。,c++,opencv,linker,undefined-reference,surf,C++,Opencv,Linker,Undefined Reference,Surf,这是密码 #include <cstdio> #include <string> #include <vector> #include "opencv/cv.h" #include "opencv/highgui.h" #include "opencv2/features2d/features2d.hpp" using namespace cv; using namespace std; int main(int argc, char **argv){

这是密码

#include <cstdio>
#include <string>
#include <vector>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv2/features2d/features2d.hpp"


using namespace cv;
using namespace std;

int main(int argc, char **argv){
        if (argc <3) {
            cout << "Usage: " << argv[0] << " imageLocation1 imageLocation2" << endl;

            return -1;
        }

        Mat source1 = imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
        Mat source2 = imread(argv[2],CV_LOAD_IMAGE_GRAYSCALE);
        if(source1.empty() || source2.empty()){
        printf("Can't load all the images!");
        return -1;
        }   

//Initialise the Wrapping Class for Surf()
    SurfFeatureDetector detector(400);

//detect : first param: Image, second param: vector (output)

    vector<KeyPoint> keypoints1,keypoints2;

    detector.detect(source1,keypoints1);
    detector.detect(source2,keypoints2);

//Initialise wrapping class for descriptors computing using SURF() class.
    SurfDescriptorExtractor extractor;

//Compute: Input:image, keypoints Output:descriptors
    Mat descriptors1,descriptors2;

    extractor.compute(source1,keypoints1,descriptors1);
    extractor.compute(source2,keypoints2,descriptors2);

//Initialise BruteForceMatcher: For each descriptor in the first set, this matcher finds the closest descriptor in the second set by trying each on (=brute)
    BruteForceMatcher< L2<float> > matcher;
    vector< DMatch > matches;

//match: execute the matcher!
    matcher.match(descriptors1,descriptors2, matches);

//Draw the matches with drawMatches
    Mat target;
    drawMatches(source1,keypoints1,source2,keypoints2,matches,target); 

    imshow("Matches", target);

    waitKey(0);

    return 0;
}
我真的不知道问题出在哪里


问题很可能是连接线不正确。不幸的是,您没有说明您的链接线路是什么,因此无法提供进一步的帮助。阅读可能会有所帮助。

如果您使用的是opencv2.4或svn中的trunk,SURF和SIFT接口将发生更改。

如果您使用的是opencv 2.4,SURF和SIFT接口将更改为非自由文件夹。您可以通过包含这一行来使用它

#include <opencv2/nonfree/features2d.hpp>

然后你可以像以前一样使用SurfFeatureDetector。

对于SURF,@Mingyi Wu回答道。请给BruteForceMatcher


在将OpenCV从2.3.1升级到2.4.5后,我遇到了这个问题,我通过链接OpenCV_nonfree解决了这个问题,并为我的项目添加了必要的标题:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/imgproc/imgproc.hpp"

我在安装ROS后遇到了类似的问题。问题是我链接到了错误的库


我通过在CMakeLists.txt中添加以下行修复了链接错误:对于ocv 2.4.9,link_目录/opt/ros/groovy/lib

:include是冲浪的位置。在项目设置中,选择配置属性、链接器、输入,然后将opencv_nonfree249d.lib添加到其他依赖项。对于这些例子,ocv文档中的以下示例可以很好地工作:-

对不起,我忘了这一点。编辑第一篇文章。找到它:我忘了包括图书馆的opencv_功能2d。我有完全相同的问题,你是如何包括opencv_功能2d的?我确实设置了opencv_库opencv_核心opencv_highgui opencv_imgproc opencv_功能2d,但它不起作用。添加动态库链接libopencv_nonfree.so和libopencv_功能2d。那么您如何链接opencv_nonfree??
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/legacy/legacy.hpp>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/imgproc/imgproc.hpp"