Ask Your Question
0

Can a features matrix be an image with 3 channels? (knn search algorithm, flann module)

asked 2017-05-31 04:34:19 -0600

Msharsha gravatar image

What are the dimensions of features matrix ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-06-01 03:46:05 -0600

berak gravatar image

updated 2017-06-01 09:22:11 -0600

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);
edit flag offensive delete link more

Comments

What actually does indices refer to in a color image ?

Msharsha gravatar imageMsharsha ( 2017-06-01 05:51:42 -0600 )edit

the cluster numbers (irrespective of context) of the K closest neighbours.

berak gravatar imageberak ( 2017-06-01 05:54:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-05-31 04:31:42 -0600

Seen: 265 times

Last updated: Jun 01 '17