Ask Your Question

Revision history [back]

Flann descriptor save and load doesn't work

void testSaveAndLoad(Mat descriptors, string outputFile) { vector<string> images;

flann::LshIndexParams lshIndexParams(20,10,2);
flann::Index kdtree(descriptors, lshIndexParams, cvflann::FLANN_DIST_HAMMING);

cout << "outputting index file to disk: " << "\n";

// just to check whether loaded ones are same or similar    
writeMatToFile(descriptors, "before_save.dat");
kdtree.save(outputFile);

// saving done .. now load
Mat mat = Mat(descriptors.rows, descriptors.cols, CV_8UC1);

// read saved indices
 flann::Index kdtree1(mat,
                    flann::SavedIndexParams(outputFile), cvflann::FLANN_DIST_HAMMING);

writeMatToFile(mat, "after_save.dat");

cout << "Loaded mat of size " << mat.rows << " " << mat.cols << "\n";

// prepare to output indices and distances
Mat indices = Mat(descriptors.rows, 2, CV_32S);
Mat dists = Mat(descriptors.rows, 2, CV_32S);
kdtree1.knnSearch(descriptors, indices, dists, 2);

}

before_save.dat:

%YAML:1.0
mat: !!opencv-matrix
   rows: 6342
   cols: 61
   dt: u
   data: [ 1, 0, 140, 7, 1, 238, 55, 0, 0, 0, 0, 0, 0, 0, 0, 128, 25,
       122, 134, 6, 0, 0, 240, 248, 227, 1, 3, 227, 249, 255, 62, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 24, 0, 0, 128, 48, 230, 15, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 128, 25, 59, 243, 51, 6, 16, 64, 252, 255, 199, 16, 255,
       7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 6, 0, 60, 0, 0, 0, 0, 0, 0,
       0, 0, 192, 14, 160, 3, 112, 0, 7, 16, 0, 0, 0, 0, 0, 0, 254, 63,
.........



after_save.dat:

%YAML:1.0
mat: !!opencv-matrix
   rows: 6342
   cols: 61
   dt: u
   data: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
.......

And knnSearch throws segfaults during the matching.

Thanks

Flann descriptor save and load doesn't work

void testSaveAndLoad(Mat descriptors, string outputFile) {
vector<string> images;

images;
flann::LshIndexParams lshIndexParams(20,10,2);
 flann::Index kdtree(descriptors, lshIndexParams, cvflann::FLANN_DIST_HAMMING);
 cout << "outputting index file to disk: " << "\n";
 // just to check whether loaded ones are same or similar
 writeMatToFile(descriptors, "before_save.dat");
 kdtree.save(outputFile);
 // saving done .. now load
 Mat mat = Mat(descriptors.rows, descriptors.cols, CV_8UC1);
 // read saved indices
 flann::Index kdtree1(mat,
 flann::SavedIndexParams(outputFile), cvflann::FLANN_DIST_HAMMING);

writeMatToFile(mat, "after_save.dat");

"after_save.dat");
cout << "Loaded mat of size " << mat.rows << " " << mat.cols << "\n";
 // prepare to output indices and distances
 Mat indices = Mat(descriptors.rows, 2, CV_32S);
 Mat dists = Mat(descriptors.rows, 2, CV_32S);
 kdtree1.knnSearch(descriptors, indices, dists, 2);
 }

}

before_save.dat:

%YAML:1.0
mat: !!opencv-matrix
   rows: 6342
   cols: 61
   dt: u
   data: [ 1, 0, 140, 7, 1, 238, 55, 0, 0, 0, 0, 0, 0, 0, 0, 128, 25,
       122, 134, 6, 0, 0, 240, 248, 227, 1, 3, 227, 249, 255, 62, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 24, 0, 0, 128, 48, 230, 15, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 128, 25, 59, 243, 51, 6, 16, 64, 252, 255, 199, 16, 255,
       7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 6, 0, 60, 0, 0, 0, 0, 0, 0,
       0, 0, 192, 14, 160, 3, 112, 0, 7, 16, 0, 0, 0, 0, 0, 0, 254, 63,
.........



after_save.dat:

%YAML:1.0
mat: !!opencv-matrix
   rows: 6342
   cols: 61
   dt: u
   data: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
.......

And knnSearch throws segfaults during the matching.

Thanks

click to hide/show revision 3
retagged

updated 2014-05-28 09:50:27 -0600

berak gravatar image

Flann descriptor save and load doesn't work

void testSaveAndLoad(Mat descriptors, string outputFile) {
    vector<string> images;

    flann::LshIndexParams lshIndexParams(20,10,2);
    flann::Index kdtree(descriptors, lshIndexParams, cvflann::FLANN_DIST_HAMMING);

    cout << "outputting index file to disk: " << "\n";

    // just to check whether loaded ones are same or similar    
    writeMatToFile(descriptors, "before_save.dat");
    kdtree.save(outputFile);

    // saving done .. now load
    Mat mat = Mat(descriptors.rows, descriptors.cols, CV_8UC1);

    // read saved indices
     flann::Index kdtree1(mat,
                        flann::SavedIndexParams(outputFile), cvflann::FLANN_DIST_HAMMING);

   writeMatToFile(mat, "after_save.dat");

    cout << "Loaded mat of size " << mat.rows << " " << mat.cols << "\n";

    // prepare to output indices and distances
    Mat indices = Mat(descriptors.rows, 2, CV_32S);
    Mat dists = Mat(descriptors.rows, 2, CV_32S);
    kdtree1.knnSearch(descriptors, indices, dists, 2);
 }

before_save.dat:

%YAML:1.0
mat: !!opencv-matrix
   rows: 6342
   cols: 61
   dt: u
   data: [ 1, 0, 140, 7, 1, 238, 55, 0, 0, 0, 0, 0, 0, 0, 0, 128, 25,
       122, 134, 6, 0, 0, 240, 248, 227, 1, 3, 227, 249, 255, 62, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 24, 0, 0, 128, 48, 230, 15, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 128, 25, 59, 243, 51, 6, 16, 64, 252, 255, 199, 16, 255,
       7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 6, 0, 60, 0, 0, 0, 0, 0, 0,
       0, 0, 192, 14, 160, 3, 112, 0, 7, 16, 0, 0, 0, 0, 0, 0, 254, 63,
.........



after_save.dat:

%YAML:1.0
mat: !!opencv-matrix
   rows: 6342
   cols: 61
   dt: u
   data: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
.......

And knnSearch throws segfaults during the matching.

Thanks