0

I am trying to create a class where I shall find KeyPoints in an image. However, I get a ridiculous error I cannot figure out how to solve.

The problem is now that

this->detector 

is zero, so it is for some reason not initialized properly. I have searched on google but I haven't found anything.

My headerfile looks as follows

    /*
 * 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_ */

And constructor looks as

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

and a function I will use looks as:

// 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);
}

I use cmake and (part of) my CMakeLists.txt looks like:

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

Can it be that

${OpenCV_LIBS}

does not include libopencv_nonfree.so ?

Regards

El_Loco
  • 1,716
  • 4
  • 20
  • 35
  • There's nothing wrong with your code. Did you include all the necessary .libs into your project ? – pwwpche Jan 21 '15 at 15:36
  • I put my CMakeLists.txt in the question – El_Loco Jan 21 '15 at 15:42
  • What is your "Ridiculous" error? Can you put it with full stack trace – ha9u63a7 Jan 21 '15 at 15:44
  • #0 0x00007ffff792d02e in cv::FeatureDetector::detect(cv::Mat const&, std::vector >&, cv::Mat const&) const () from /usr/local/lib/libopencv_features2d.so.2.4 #1 0x000000000041be7b in FindKeyPoints::detectKeypoints(cv::Mat&, cv::Mat&) () #2 0x000000000041b79a in main () – El_Loco Jan 21 '15 at 16:19

1 Answers1

0

I suspect the error is that I had only included

opencv2/nonfree/features2d.hpp

and not also

opencv2/nonfree/nonfree.hpp.
El_Loco
  • 1,716
  • 4
  • 20
  • 35