bus error while reading Flann Index from File

asked 2013-09-21 02:41:17 -0600

qube gravatar image

updated 2013-09-21 02:42:07 -0600

#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include <time.h>


int main( int argc, char** argv )
{
  cv::Mat img_object = cv::imread( argv[1], 1);
  cv::Mat img_scene = cv::imread( argv[2], 1);

  std::vector<cv::KeyPoint> keypoints_object, keypoints_scene;
  cv::Mat descriptors_object; 
  cv::Mat descriptors_scene;

  int Threshl=60;
  int Octaves=4; //(pyramid layer) from which the keypoint has been extracted
  float PatternScales=1.0f;
  cv::BRISK detector2(Threshl,Octaves,PatternScales);
  detector2.create("Feature2D.BRISK");


  detector2.detect( img_object, keypoints_object );
  detector2.detect( img_scene, keypoints_scene );

  detector2.compute(img_object,keypoints_object,descriptors_object);
  detector2.compute(img_scene,keypoints_scene,descriptors_scene);

  std::cout<< descriptors_object.size() << std::endl;
  std::cout<< descriptors_object.isContinuous() << std::endl;

 cv::flann::Index idx2(descriptors_object, cv::flann::LshIndexParams(20,10,2) ,cvflann::FLANN_DIST_HAMMING);
 idx2.save("flann.bin"); 

  cv::Mat flann_descriptors(2075,64,0);
  cv::flann::SavedIndexParams idxfile("flann.bin");
  cv::flann::Index idx(flann_descriptors, idxfile ,cvflann::FLANN_DIST_HAMMING);

  cv::Mat indices,dists;
  idx.knnSearch(descriptors_scene,indices,dists,1);

  for(int i=0;i < indices.rows ; i++){
    std::cout << indices.at<int>(0,i) << "," << dists.at<int>(0,i)  << std::endl;
 }
}

The above code throws a bus error when index saved and read from file. The same code works when the index is created directly without using file.

edit retag flag offensive close merge delete

Comments

I am using the latest OpenCv as of now 2.4.6.1

qube gravatar imageqube ( 2013-09-21 02:48:35 -0600 )edit