First time here? Check out the FAQ!

Ask Your Question
4

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

asked Nov 11 '12

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

Preview: (hide)

1 answer

Sort by » oldest newest most voted
15

answered Nov 11 '12

Simone gravatar image

updated Nov 11 '12

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.

Preview: (hide)

Comments

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

ipunished gravatar imageipunished (Nov 11 '12)edit

thank you very much too! the information was very useful

Olbitla gravatar imageOlbitla (Dec 5 '12)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 (Oct 13 '17)edit

Question Tools

Stats

Asked: Nov 11 '12

Seen: 9,950 times

Last updated: Nov 11 '12