[SOLVED]use knnSearch, terminate called after throwing an instance of 'cvflann::anyimpl::bad_any_cast' [closed]
output error:
terminate called after throwing an instance of 'cvflann::anyimpl::bad_any_cast'
My code:
cvflann::Matrix<uchar> data((uchar*) fetaures.data, fetaures.rows,
fetaures.cols);
cvflann::Index<cvflann::Hamming<uchar>> flann_index(data,
cvflann::LshIndexParams(10, 10, 10));
flann_index.buildIndex();
Ptr<ORB> detector = ORB::create(minHessian);
std::vector<cv::KeyPoint> keypoints;
cv::Mat queryDescriptors;
detector->detectAndCompute(Q, noArray(), keypoints, queryDescriptors);
Mat disMat(cv::Size(queryDescriptors.rows, queryDescriptors.cols), CV_32F);
Mat indeicesMat(cv::Size(queryDescriptors.rows, queryDescriptors.cols),
CV_32F);
cvflann::Matrix<unsigned char> queries((unsigned char*) queryDescriptors.data,
queryDescriptors.rows, queryDescriptors.cols);
cvflann::Matrix<int> indices((int*) indeicesMat.data, queryDescriptors.rows,
queryDescriptors.cols);
cvflann::Matrix<int> dists((int*) disMat.data, queryDescriptors.rows,
queryDescriptors.cols);
flann_index.knnSearch(queries, indices, dists, knn,
cvflann::SearchParams(32));
And I found cvflann:index
and cv::flann::index
, which should i use?
https://answers.opencv.org/question/1...
i see that post. but the method there doesn't work for me
why not use BFMatcher(HAMMING) with ORB ? (what do you need a knn index search for ?)
cv::flann::Index flann_index(samples_32f, cv::flann::LshIndexParams(10, 10, 10));
can work.
^^ not if you use ORB
to search image lable
samples_32f
is a descriptor for many picturesfor (int i = 1; i < descriptors.size(); i++) { cv::vconcat(samples_32f, descriptors.at(i), samples_32f); }