C++/OpenCV - How can i get my image after using flann::index? (With BoF)

asked 2014-08-19 05:20:12 -0600

lilouch gravatar image

I use BoW with SURF and FlannBasedMatcher for image retrieval inside a database. I extracted all my features of my database (Training) using SURF , then i builded the vocabulary and finally i got the BOF frequency histograms for each pictures inside my database (training).

to be clear, i don't put the details of all of this process but tell me if you need some details.

So at this step i have :

  • cv::Mat allDescriptors --> descriptors of my all database (training)

  • cv::Mat Vocabulary --> codebook representation

  • cv::Mat responseDatabase --> frequency histograms for each pictures inside my database

Then i used a query and compute its reponse according to the vocabulary computed just before. Finally i have this data :

  • cv::Mat responseQuery --> frequency histogram of my query

Now i have some difficulties. I used

 cv::flann::Index flannIndex(responseDatabase, cv::flann::KDTreeIndexParams(), cvflann::FLANN_DIST_EUCLIDEAN);
cv::Mat results, dists;
int k=2;
flannIndex.knnSearch(responseQuery, results, dists, k, cv::flann::SearchParams() );

It worked well and i got this results :

  • cv::Mat results --> [38, 117]

  • cv::Mat dist --> [0.0010655867, 0.013091294]

But now with those results, how can i recover the two pictures corresponding to my 2 nearest neighbors ? Indeed, i don't have any trace of the pictures inside each of my data.

Maybe, i missed one step but which one ?


edit retag flag offensive close merge delete


hmm, if your responseDatabase had 1 row per image/histogram, [38, 117] should be the 2 closest indices from the responseDatabase

berak gravatar imageberak ( 2014-08-19 05:29:25 -0600 )edit

Yes i know but the responseDatabase correspond to histograms and not the picture ! I would like to display the picture corresponding to this histogram...Do you know ?

lilouch gravatar imagelilouch ( 2014-08-19 05:32:18 -0600 )edit

you would have to keep the image list used while acquiring the surf features

berak gravatar imageberak ( 2014-08-19 05:39:04 -0600 )edit

Yes this is what i did. Simply. But i don't know if it was the best way. Anyway thank !

lilouch gravatar imagelilouch ( 2014-08-20 03:00:08 -0600 )edit

@lilouch, discovered any other way to save the flann index scalable, savable and editable to disk?

bad_keypoints gravatar imagebad_keypoints ( 2014-10-20 01:52:49 -0600 )edit