How to save and load FlannBasedMatcher

asked 2012-08-16 12:36:41 -0600

zhfkt gravatar image

Hi,

Training an OpenCV DescriptorMatcher can be a time consuming operation if the training image set is large.Reference to this post

http://stackoverflow.com/questions/9248012/saving-and-loading-flannbasedmatcher?rq=1

There exists read and write method to load and save FlannBasedMatcher.

   virtual void read( const FileNode& );

   virtual void write( FileStorage& ) const;

I try this method and find that the trained DescriptorMatcher data is strange.My code is

    FlannBasedMatcher matcher;
    FileStorage matcher_fs(matcher_string.c_str(), FileStorage::WRITE); 

    vector<Mat> ref_his_vector;
    ref_his_vector.push_back(ref_his);
    matcher.add(ref_his_vector);
    matcher.train();

    matcher.write(matcher_fs);
    matcher_fs.release();

Mat ref_his is defined above

And the result on the disk is

image description

In fact,trainning data in the FlannBasedMatcher exists 154 descriptors

image description

I'm not sure whether there is anything wrong with my code.My opencv version is 2.4.2.

edit retag flag offensive close merge delete