Flan Index - Save and Load Problem

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Flan Index - Save and Load Problem

opencv-users mailing list
Dear all,

I'm trying to implement Flann Index in OpenCV. Let me tell about my
implementation step-by-step:

1) I extracted SURF features from train images and concatenated all. Then
saved descriptors and flann index like this:


*     FileStorage fs("descriptors.yml", FileStorage::WRITE);*
*     write(fs, "descriptors", descriptors);*
*     Index flann_index_saved(descriptors, KMeansIndexParams());**
flann_index_saved.save("tmp_twitter.fln");*

2) I extracted SURF features from query image.

3) I loaded flann index like this:


*     FileStorage fsRead(yamlFile, FileStorage::READ);*
*     Mat indexMat(Size(64, sampleSize), CV_32FC1);*
*     fsRead["descriptors"] >> indexMat;*
*     Index flann_index_loaded;**     flann_index_loaded.load(indexMat,
indexFilePath);*

4) For matching, I used knnSearch:



*     Mat queryDesc, indicesResult, distsResults;     Index fIndex;**
fIndex.knnSearch(queryDesc, indicesResult, distsResults, 1);*

But nothing happens. Only "no source available for..." exception occurs. I
think I couldn't implement Flann in OpenCV.

I'm using Ubuntu 12.04, OpenCV 2.4.10, Eclipse CDT+.

Please help me...

Kind regards,


ömür
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Flan Index - Save and Load Problem

opencv-users mailing list
Dear all again,

I resolved the problem. Let me reply my own question :)

1) I extracted SURF features from train images and concatenated all. Then
saved descriptors and flann index like this:








*  Index flannIndex;     Mat indexDescriptors;     IndexParams
indexParams;     indexParams = *new KMeansIndexParams();     flannIndex =
*new Index(indexDescriptors, indexParams);     FileStorage
fs(descriptorName, FileStorage::WRITE);     write(fs, "descriptors",
indexDescriptors);     flannIndex.save(indexName);*

2) I extracted SURF features from query image.

3) I loaded flann index like this:








* Index flannIndexSaved;     IndexParams indexParamsSaved;     Mat
indexMat;     indexMat = Mat(Size(64, sampleSize), CV_32F);     FileStorage
fs(yamlFile, FileStorage::READ);     fs["descriptors"] >> indexMat;
indexParamsSaved = *new SavedIndexParams(indexFilePath);
flannIndexSaved = *new Index(indexMat, indexParamsSaved);*

4) For matching, I used knnSearch:


*  Mat queryDesc, indicesResult, distsResults;
flannIndexSaved.knnSearch(queryDesc, indicesResult, distsResults, 1);*

This works fine :)

ömür


2016-02-29 13:14 GMT+02:00 Ömür <[hidden email]>:

> Dear all,
>
> I'm trying to implement Flann Index in OpenCV. Let me tell about my
> implementation step-by-step:
>
> 1) I extracted SURF features from train images and concatenated all. Then
> saved descriptors and flann index like this:
>
>
> *     FileStorage fs("descriptors.yml", FileStorage::WRITE);*
> *     write(fs, "descriptors", descriptors);*
> *     Index flann_index_saved(descriptors, KMeansIndexParams());**
> flann_index_saved.save("tmp_twitter.fln");*
>
> 2) I extracted SURF features from query image.
>
> 3) I loaded flann index like this:
>
>
> *     FileStorage fsRead(yamlFile, FileStorage::READ);*
> *     Mat indexMat(Size(64, sampleSize), CV_32FC1);*
> *     fsRead["descriptors"] >> indexMat;*
> *     Index flann_index_loaded;**     flann_index_loaded.load(indexMat,
> indexFilePath);*
>
> 4) For matching, I used knnSearch:
>
>
>
> *     Mat queryDesc, indicesResult, distsResults;     Index fIndex;**
> fIndex.knnSearch(queryDesc, indicesResult, distsResults, 1);*
>
> But nothing happens. Only "no source available for..." exception occurs. I
> think I couldn't implement Flann in OpenCV.
>
> I'm using Ubuntu 12.04, OpenCV 2.4.10, Eclipse CDT+.
>
> Please help me...
>
> Kind regards,
>
>
> ömür
>
>
Loading...