OpenCV FeatureDetector未初始化

时间:2015-01-21 15:27:36

标签: c++ opencv feature-detection

我正在尝试创建一个类,我将在图像中找到KeyPoints。但是,我得到了一个荒谬的错误,我无法弄清楚如何解决。

现在的问题是

this->detector 

为零,因此出于某种原因未正确初始化。我在谷歌搜索过但我没有找到任何东西。

我的头文件如下所示

    /*
 * FindKeyPoints.h
 *
 *  Created on: Jan 21, 2015
 *      Author: erikbylow
 */

#ifndef FINDKEYPOINTS_H_
#define FINDKEYPOINTS_H_

#include <vector>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv/cxcore.h>
using namespace std;

class FindKeyPoints {

private:
    // Create vector of KeyPoints to store the detected keypoint in
    vector<cv::KeyPoint> keyPointsOld;
    vector<cv::KeyPoint> keyPointsNew;
    // Threshold for similarity
    const int THRESHOLD = 10;

    // Instance(?) DescriptionExtractor and descriptor
    cv::Ptr<cv::DescriptorExtractor> descriptionExtractor;
    cv::Ptr<cv::FeatureDetector> detector;

public:
    FindKeyPoints(const string &METHOD);
    virtual ~FindKeyPoints();
    void detectKeypoints(cv::Mat& imgNew, cv::Mat& imgOld);
};

#endif /* FINDKEYPOINTS_H_ */

构造函数看起来像

FindKeyPoints::FindKeyPoints(const string &METHOD) {
    cout<<METHOD<<endl;
    cv::initModule_features2d();
    this->detector = cv::FeatureDetector::create("SURF");
    //this->descriptionExtractor = cv::DescriptorExtractor::create(METHOD);
}

我将使用的函数看起来像:

// Input: The new image and the old image. Find Keypoints and extract the descriptors.
void FindKeyPoints::detectKeypoints(cv::Mat& imgNew,
        cv::Mat& imgOld) {
    if (this->detector == 0){
        cout<<"Hej"<<endl;
    }
//  this->detector->detect(imgNew, keyPointsNew);
//  this->detector->detect(imgOld, keyPointsOld);
}

我使用cmake和(部分)我的CMakeLists.txt看起来像:

TARGET_LINK_LIBRARIES(${PROJECT_NAME} groundtruth ${OpenCV_LIBS} ${QT_LIBRARIES} 
${QGLViewer_LIBRARIES} ${OPENGL_gl_LIBRARY} GL
  glut)

可以吗

${OpenCV_LIBS}

不包含libopencv_nonfree.so?

此致

1 个答案:

答案 0 :(得分:0)

我怀疑错误是我只包括

opencv2/nonfree/features2d.hpp

而不是

opencv2/nonfree/nonfree.hpp.