在opencv :: flann中使用LSH索引时出错

时间:2017-03-01 17:33:27

标签: c++ opencv flann

我试图在opencv中使用flann的LSH实现:

const int mySizes[1]={100};
cv::Mat descriptors1 = cv::Mat::zeros(1,mySizes,CV_32F);
cv::Mat descriptors2 = cv::Mat::zeros(1,mySizes,CV_32F);

cv::Ptr<cv::DescriptorMatcher> matcher_;
matcher_ = new cv::FlannBasedMatcher(new cv::flann::LshIndexParams(20,10,2));
std::vector<cv::DMatch> matches;
matcher_->match(descriptors1, descriptors2, matches);

std::cout << matches[0].distance << std::endl;

更确切地说,我希望使用descriptors1获取descriptors2matches[0].distance之间的LSH距离。

但是当我运行这段代码时,我得到了:

OpenCV Error: Unsupported format or combination of formats (type=5
) in buildIndex_, file /home/lpuglia/repository/opencv/modules/flann/src/miniflann.cpp, line 315
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/lpuglia/repository/opencv/modules/flann/src/miniflann.cpp:315: error: (-210) type=5
 in function buildIndex_

代码非常简单,我做错了什么?

1 个答案:

答案 0 :(得分:0)

使用了错误的descritptor类型,解决方案:

cv::UMat descriptors1 = cv::UMat (1, 100, CV_8UC1);
cv::UMat descriptors2 = cv::UMat (1, 100, CV_8UC1);