c++ - flann索引使用LshIndexParams需要什么类型的数据?

标签 c++ opencv flann

我想使用 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/

相关文章:

python-3.x - 为什么向图像添加高斯噪声会产生白屏?

c++ - 找到flann矩阵类型中出现频率最高的元素

c++ - 如何使用 opencv 特征匹配检测复制移动伪造

C++/OpenCV - 使用 flann::index 后如何获取我的图像? (与 BoF)

c++ - 释放调用者或被调用者的内存?

python - 如何使用 openCV python 读取 Youtube 直播?

c++ - Linux fork 和 Kill 后停止创建核心转储文件

Python过滤器去除图像中的异常值

c++ - 如何使用gcc在centos 6.4中使用gcc64的旧版本进行编译

c++ - 为什么派生类必须重新定义重写的基类方法