我想获得一个OpenCV的FABMAP实现的最小工作示例。为了实现这一目标,我从this file复制了代码。我使用的是与示例代码提供商不同的OpenCV版本(在我的例子中是2.4.8)并且必须更改原始行
Ptr<DescriptorExtractor> extractor =
new SurfDescriptorExtractor(1000, 4, 2, false, true);
到
Ptr<DescriptorExtractor> extractor =
DescriptorExtractor::create("SURF");
不幸的是,现在我得到了一个我无法解决的分段错误(我评论了这一行)。此外,我发现extractor
是空指针,而matcher
则不是。可能是nullpointer extractor
造成了麻烦吗?我该如何解决这种情况?
我使用Ubuntu 14.04和g ++进行编译(c ++ 11)。
要重现这一点,您必须下载this directory。我的最小(几乎)工作的例子:
#include "opencv2/opencv.hpp"
#include "opencv2/features2d/features2d.hpp"
using namespace cv;
using namespace std;
int main(int argc, char * argv[]) {
string dataDir = "fabmap_data/";
FileStorage fs;
//load/generate vocabulary
fs.open(dataDir + string("vocab_small.yml"), FileStorage::READ);
Mat vocab;
fs["Vocabulary"] >> vocab;
fs.release();
//generate test data
Ptr<FeatureDetector> detector =
new DynamicAdaptedFeatureDetector(
AdjusterAdapter::create("STAR"), 130, 150, 5);
Ptr<DescriptorExtractor> extractor =
DescriptorExtractor::create("SURF"); // extractor seems to be a nullpointer (addres:: 0x0)
Ptr<DescriptorMatcher> matcher =
DescriptorMatcher::create("FlannBased");
BOWImgDescriptorExtractor bide(extractor, matcher);
bide.setVocabulary(vocab);
string imageName = "stlucia_test_small0000.jpeg";
Mat frame;
Mat bow;
vector<KeyPoint> kpts;
frame = imread(dataDir + imageName);
detector->detect(frame, kpts);
bide.compute(frame, kpts, bow); // I get a segmentation fault at this line!
return 0;
}