Ask Your Question
4

To save vector "KeyPoint" to file using builtin write function

asked 2012-11-11 09:47:35 -0600

ipunished gravatar image

Hi,

I want to write a vector of detected Keypoints to file and while I was told it can be done through operator overloading, I found out a function in the keypoint class documentation.

The documentation here shows a function called write..

// reading/writing a vector of keypoints to a file storage
void write(FileStorage& fs, const string& name, const vector<KeyPoint>& keypoints);
void read(const FileNode& node, vector<KeyPoint>& keypoints);

So basically there is a function to write the vector to file.. can some one please explain this and also, an example on how to use this would be great.

Thank you

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
15

answered 2012-11-11 10:15:38 -0600

Simone gravatar image

updated 2012-11-11 10:19:25 -0600

Hi,

it's actually simple. In order to save your keypoints

 vector<Keypoint> mykpts;
 FileStorage fs("keypoints.yml", FileStorage::WRITE);
 write( fs , "aNameYouLike", mykpts );
 fs.release();

This will store your keypoints in a file named keypoints.yml and the node containing the data is named "aNameYouLike". This will be used to read back the keypoints from the file:

  vector<Keypoint> mykpts2;
  FileStorage fs2("keypoints.yml", FileStorage::READ);
  FileNode kptFileNode = fs2["aNameYouLike"];
  read( kptFileNode, mykpts2 );
  fs2.release();

You may want to check the XML/YAML file storage documentation for more information.

Hope it helps

S.

edit flag offensive delete link more

Comments

Thank you. That was very helpful. I wish I could upvote this more than once.

ipunished gravatar imageipunished ( 2012-11-11 10:38:51 -0600 )edit

thank you very much too! the information was very useful

Olbitla gravatar imageOlbitla ( 2012-12-05 13:39:01 -0600 )edit

i am using XML storage way.It can save keypoint perfectly of first image. now i want that i used for loop and it save my image keypoint one by one.so how can i do it.

salman gravatar imagesalman ( 2017-10-13 08:58:14 -0600 )edit

Question Tools

Stats

Asked: 2012-11-11 09:47:35 -0600

Seen: 9,860 times

Last updated: Nov 11 '12