I'm not sure what you really expect: The code I provide you with is just an example to show how file storage works in OpenCV C ++ bindings. It is assumed that you write all the key points separately in the XML file, and their name is their position in the vector in which they were saved.
It is also assumed that when you read them, you know the number of them that you want to read, and if not, the code is a bit more complicated. You will find a way (if, for example, you are reading a file and checking what it gives you, if it does not give you anything, then thereβs no point in reading) - this is just an idea, you should find a solution, maybe this piece of code will be enough for you. I must clarify that I am using ostringstream to put an integer in a string and, by the way, change the place where it will be written in the * .yml file.
//TO WRITE vector<Keypoint> myKpVec; FileStorage fs(filename,FileStorage::WRITE); ostringstream oss; for(size_t i;i<myKpVec.size();++i) { oss << i; fs << oss.str() << myKpVec[i]; } fs.release(); //TO READ vector<Keypoint> myKpVec; FileStorage fs(filename,FileStorage::READ); ostringstream oss; Keypoint aKeypoint; for(size_t i;i<myKpVec.size();<++i) { oss << i; fs[oss.str()] >> aKeypoint; myKpVec.push_back(aKeypoint); } fs.release();
Julien
jmartel
source share