我想使用 LSH 来加快搜索速度,我发现在 opencv flann 中可以通过使用 LshIndexParams 来做到这一点?问题是我无法正确设置格式。我用词袋来生成一个 mat 输出并将其提供给 flann,但我总是出错。
OpenCV Error: Unsupported format or combination of formats (type=2
) 在 buildIndex_ 中,文件/home/vampire/opencv-2.4.8/modules/flann/src/miniflann.cpp,第 315 行 在抛出“cv::Exception”实例后调用终止 what():/home/vampire/opencv-2.4.8/modules/flann/src/miniflann.cpp:315: 错误: (-210) type=2 在函数 buildIndex_ 中
部分代码如下:
Mat img_BOWdescriptor=BOW_descriptors(path);
cout<<img_BOWdescriptor<<endl;
img_BOWdescriptor.convertTo(img_BOWdescriptor,img_BOWdescriptor.rows,img_BOWdescriptor.cols,CV_32F);
cout<<img_BOWdescriptor<<endl;
cout<<"done"<<endl;
cout<<"ini flann index......"<<endl;
Mat indices = Mat(img_BOWdescriptor.rows, 1, CV_32S);
Mat dist = Mat(img_BOWdescriptor.rows, 1, CV_32F);
descriptors_all.convertTo(descriptors_all,descriptors_all.rows,descriptors_all.cols,CV_32F);
flann::Index* flann_index=new flann::Index(descriptors_all,flann::LshIndexParams(20,10,2));
cout<<"done"<<endl;
double t=(double)getTickCount();
cout<<"flann matching......"<<endl;
flann_index->knnSearch(img_BOWdescriptor, indices, dist, 1,flann::SearchParams(32));
我也试过转换成其他类型,没有人工作,有人知道怎么做吗? 在我得到结果后,我怎么知道它是否匹配?
最佳答案
试一试。我想我有同样的错误,我的工作有一个额外的参数:
cv::flann::Index kVecinos(descriptors, cv::flann::LshIndexParams(12, 20, 2), cvflann::FLANN_DIST_HAMMING);
在 cvflann 中还有其他像 cvflann::FLANN_DIST_EUCLIDEAN
关于c++ - flann索引使用LshIndexParams需要什么类型的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21085915/