First time here? Check out the FAQ!

Ask Your Question
0

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

asked May 31 '17

Msharsha gravatar image

What are the dimensions of features matrix ?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Jun 1 '17

berak gravatar image

updated Jun 1 '17

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);
Preview: (hide)

Comments

What actually does indices refer to in a color image ?

Msharsha gravatar imageMsharsha (Jun 1 '17)edit

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

berak gravatar imageberak (Jun 1 '17)edit

Question Tools

1 follower

Stats

Asked: May 31 '17

Seen: 281 times

Last updated: Jun 01 '17