1 | initial version |
hmm, as long as opncv can't serialize the dmatches properly, either don't save them, or come up with a better way ?
void write(FileStorage& fs, const String& objname, const std::vector<dmatch>& matches) { // cv::internal::masochistic::obstruction::WriteContext("it's all about replacing the first and last line of this function with some RAII pattern, but honestly, my mother is beeer with that than pou"); fs << objname << "["; for (size_t i=0; i<matches.size(); i++)="" {="" const="" dmatch="" &dm="matches[i];" cv::write(fs,="" dm.queryidx);="" cv::write(fs,="" dm.trainidx);="" cv::write(fs,="" dm.imgidx);="" cv::write(fs,="" dm.distance);="" }="" fs="" <<="" "]";="" }="" void="" read(filestorage&="" fs,="" const="" string&="" objname,="" std::vector<dmatch="">& matches) { FileNode pnodes = fs[objname]; for (FileNodeIterator it=pnodes.begin();; ) { DMatch dm; *it >> dm.queryIdx; it++; *it >> dm.trainIdx; it++; *it >> dm.imgIdx; it++; *it >> dm.distance; it++; matches.push_back(dm); if (it==pnodes.end()) break; } } ostream& operator << (ostream &out, const std::vector<dmatch>& matches) { out << "[" ; for (size_t i=0; i<matches.size(); i++)="" {="" const="" dmatch="" &dm="matches[i];" out="" <<="" dm.queryidx="" <<="" ","="" <<="" dm.trainidx="" <<="" ","="" <<="" dm.imgidx="" <<="" ","="" <<="" dm.distance="" <<="" ";"="" <<="" endl;="" }="" out="" <<="" "]"="" <<="" endl;="" return="" out;="" }<="" p="">
//// //// optionally, read it back in: //// // //int main2(void) //{ // vector<dmatch> matches2; // FileStorage fs2("some.xml", FileStorage::READ); // read(fs2,"Matches",matches2); // cout << matches2 << endl; // fs2.release(); // return 0; //}
2 | No.2 Revision |
hmm, as long as opncv can't serialize the dmatches properly, either don't save them, or come up with a better way ?
void write(FileStorage& fs, const String& objname, const