Ask Your Question
0

How to build an index of a database for image retrieval ?

asked 2014-08-18 05:10:09 -0600

lilouch gravatar image

updated 2015-12-21 06:33:54 -0600

berak gravatar image

I would like to use BoW with FLANN in order to index all my pictures inside my database.(For a CBIR project)

What i did :

  1. Loop over all ma database in order to compute the descriptors of each pictures.
  2. Clustering descriptors using K-MEAN
  3. Extraction of BoWDescriptors (Visual words) in order to have a big histogram with all my features
  4. Use FLANN Index to compute an index in each pictures

Code:

// Create Flann LSH index
cv::flann::Index flannIndex(this->descDescriptorbow, cv::flann::LshIndexParams(12, 20, 2), cvflann::FLANN_DIST_HAMMING);

cv::Mat results, dists;

int k=2; // find the 2 nearest neighbors

// search (nearest neighbor)
flannIndex.knnSearch(responseHist, results, dists, k, cv::flann::SearchParams() );

DescriptorBow contains all my BoWfeatures of my database. ResponseHist constains all my BoWfeatures of my folder which contains the test database (Some pictures to evaluate in order to find the nearest neighbor).

but i got an error

OpenCV Error: Bad argument (Only continuous arrays are supported) in buildIndex_, file /home/samoun/Bureau/opencv-2.4.6.1/modules/flann/src/miniflann.cpp, line 317 terminate called after throwing an instance of 'cv::Exception' what(): /home//opencv-2.4.6.1/modules/flann/src/miniflann.cpp:317: error: (-5) Only continuous arrays are supported in function buildIndex_

In order to see the structure of my cv::Mat descDescriptorbow i used

    ofstream compute_info("info.txt", ios::out | ios::trunc);
//responseVector = responseHist.reshape(0,1);
 compute_info << descDescriptorbow << std::endl;
 compute_info.close();

Indeed in my file.txt which contains the boWFeatures,it's not a continious array.

So i don't know if if did well or i missed a step ?

Maybe do you know a tutorial step-by-step because i'm a bit lost ?

Can someone help me ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-12-21 06:22:21 -0600

saurabheights gravatar image

In file opencv\sources\modules\flann\src\miniflann.cpp, go to line 319:

buildIndex_(void*& index, const Mat& data, const IndexParams& params, const Distance& dist = Distance())
{
   typedef typename Distance::ElementType ElementType;
   if(DataType<ElementType>::type != data.type())
       CV_Error_(CV_StsUnsupportedFormat, ("type=%d\n", data.type()));
   //This is what is **causing the error**
   if(!data.isContinuous())
       CV_Error(CV_StsBadArg, "Only continuous arrays are supported");

   /*The **reason** for the above check was because OpenCv uses flann library. The flann library uses class Matrix<ElementType> for storing Matrix data, but Opencv uses Mat for storing matrix data. Thus we need a way to convert Mat data to Matrix as done below. Here Mat is changed by considering Mat a continuous array, but your Mat is not continuous. You can circumvent this problem by using FLANN library directly and writing your own function to copy Mat(continuous or discontinuous) to Matrix. You can also file for improvement of this feature*/
   ::cvflann::Matrix<ElementType> dataset((ElementType*)data.data, data.rows, data.cols);
   IndexType* _index = new IndexType(dataset, get_params(params), dist);
  _index->buildIndex();
  index = _index;
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-08-18 05:10:09 -0600

Seen: 2,461 times

Last updated: Dec 21 '15