Search code examples
c++opencvsurffeature-descriptor

OpenCV: extractor->descriptorSize() - Segfault


I'm trying to follow this tutorial for object detection but I stuck at the beginning.

Until now my code is this:

#include <stdio.h>
#include <stdlib.h>

#include <opencv2/opencv.hpp>
#include <fstream>
#include <iostream>
#include <string>

#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

using namespace cv;
using namespace std;

int main() {

    Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("SURF");
    //Mat training_descriptors(1, extractor->descriptorSize(), extractor->descriptorType());

    extractor->descriptorSize();

    return 0;
}

The following line extractor->descriptorSize(); gives a Segmentation fault (core dumped) and I don't know why. Do you have any ideas?


Solution

  • I found out that the nonfree module of OpenCV was not installed. After installation I included the nonfree library #include <opencv2/nonfree/nonfree.hpp> and then called cv::initModule_nonfree();. The problem is solved.