Can a features matrix be an image with 3 channels? (knn search algorithm, flann module)
What are the dimensions of features matrix ?
yes, but you have to "flatten" (reshape) the Mat to an 1d float vector
// assuming, you have a vector<Mat> vecs for training:
Mat trainData; // one row for each train Mat
// WARNING ! YOU HAVE TO KEEP THE trainData MAT ALIVE UNTIL THE PREDICTION !!!
// (flann does dirty things with pointers there)
for (size_t i=0; i<vecs.size(); i++) {
Mat m = vecs[i].reshape(1,1);
m.convertTo(m, CV_32F);
trainData.push_back(m);
}
cv::Ptr<cv::flann::Index> =
makePtr<cv::flann::Index>(trainData, cv::flann::LinearIndexParams(), cvflann::FLANN_DIST_L2);
Mat test = ...;
test = test.reshape(1,1);
test.convertTo(test, CV_32F);
int K=5;
cv::flann::SearchParams params;
cv::Mat dists;
cv::Mat indices;
index->knnSearch(testFeature, indices, dists, K, params);
Asked: May 31 '17
Seen: 281 times
Last updated: Jun 01 '17
How to use the LshIndexParams?
Using FLANN with binary descriptors (Brief,ORB)
How can I find out the number of results in a FLANN radiusSearch
Feature Matching with FLANN - Exception on "nonfree_init.cpp"
what is the FLANN version in latest OPENCV2.4.3?
How to detect(rotation scale invariant) a insect from a picture?