Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Actually something like

cv::flann::GenericIndex<cv::L1<float> > index()

should work or worked some while ago. However, I get a compiler error here. So afaik - maybe I am wrong here! - this works only with the cvflann-namespace:

cvflann::Index<cvflann::ChiSquareDistance<float> > flann_index(flann_m, cvflann::LinearIndexParams());

However, then you also need to convert your flann_m and your other matrices to flann-matrices, e.g.

cvflann::Matrix<float> samplesMatrix((float*)flann_m.data, flann_m.rows, flann_m.cols);

But in the case you need to use the cvflann-namespace I would immediatly chose to use the original up-to-date flann-library (http://www.cs.ubc.ca/~mariusm/index.php/FLANN/FLANN), their you need to do the same steps but have the advantage of a bug-fixed version (be aware that you don't mix the flann:: and the cv::flann:: namespaces) - this is what I actually use. Let me know if you get it working with the cv::flann::-namespace. Good luck!

Actually something like

cv::flann::GenericIndex<cv::L1<float> > index()

should work or worked some while ago. However, I get a compiler error here. So afaik - maybe I am wrong here! - this works only with the cvflann-namespace:

cvflann::Index<cvflann::ChiSquareDistance<float> > flann_index(flann_m, cvflann::LinearIndexParams());

However, then you also need to convert your flann_m and your other matrices to flann-matrices, e.g.

cvflann::Matrix<float> samplesMatrix((float*)flann_m.data, flann_m.rows, flann_m.cols);

But in the case you need to use the cvflann-namespace I would immediatly chose to use the original up-to-date flann-library (http://www.cs.ubc.ca/~mariusm/index.php/FLANN/FLANN), their you need to do the same steps but have the advantage of a bug-fixed version (be aware that you don't mix the flann:: and the cv::flann:: namespaces) - this is what I actually use. Let me know if you get it working with the cv::flann::-namespace. Good luck!


UPDATE: Adding working example: (both namespaces cvflann:: and flann:: (using the original library) produced same results**

int test_rank = 10;
cvflann::Matrix<float> data( (float*)all_data.data, all_data.rows, all_data.cols );
cvflann::Index<cvflann::ChiSquareDistance<float> > index(data, cvflann::LinearIndexParams());
index.buildIndex();

// make cv::Mat-header for easier access 
// (you can do the same with the dists-matrix if you need it)
cv::Mat1i ind(data.rows, test_rank);
CV_Assert(ind.isContinuous());
cvflann::Matrix<int> indices((int*) ind.data, ind.rows, ind.cols);
cvflann::Matrix<float> dists(new float[data.rows*test_rank], data.rows, test_rank);
index.knnSearch(data, indices, dists, test_rank, cvflann::SearchParams(all_data.cols-1));

Actually something like

cv::flann::GenericIndex<cv::L1<float> > index()

should work or worked some while ago. However, I get a compiler error here. So afaik - maybe I am wrong here! - this works only with the cvflann-namespace:

cvflann::Index<cvflann::ChiSquareDistance<float> > flann_index(flann_m, cvflann::LinearIndexParams());

However, then you also need to convert your flann_m and your other matrices to flann-matrices, e.g.

cvflann::Matrix<float> samplesMatrix((float*)flann_m.data, flann_m.rows, flann_m.cols);

But in the case you need to use the cvflann-namespace I would immediatly chose to use the original up-to-date flann-library (http://www.cs.ubc.ca/~mariusm/index.php/FLANN/FLANN), their you need to do the same steps but have the advantage of a bug-fixed version (be aware that you don't mix the flann:: and the cv::flann:: namespaces) - this is what I actually use. Let me know if you get it working with the cv::flann::-namespace. Good luck!


UPDATE: Adding working example: (both namespaces cvflann:: and flann:: (using the original library) produced same results**results

int test_rank = 10;
cvflann::Matrix<float> data( (float*)all_data.data, all_data.rows, all_data.cols );
cvflann::Index<cvflann::ChiSquareDistance<float> > index(data, cvflann::LinearIndexParams());
index.buildIndex();

// make cv::Mat-header for easier access 
// (you can do the same with the dists-matrix if you need it)
cv::Mat1i ind(data.rows, test_rank);
CV_Assert(ind.isContinuous());
cvflann::Matrix<int> indices((int*) ind.data, ind.rows, ind.cols);
cvflann::Matrix<float> dists(new float[data.rows*test_rank], data.rows, test_rank);
index.knnSearch(data, indices, dists, test_rank, cvflann::SearchParams(all_data.cols-1));