void WriteCvRectList(const list<CvRect>& listRect)
{
FileStorage fs(SAVE_FILE_NAME, FileStorage::WRITE); //建立XML檔案
if (!fs.isOpened())
{
cerr << "failed to open " << SAVE_FILE_NAME << endl;
}
fs << "VECTOR" << "[";
for (list<CvRect>::const_iterator itr = listRect.begin(); itr != listRect.end(); itr++)
{
fs << "{";
fs << "x" << itr->x;
fs << "y" << itr->y;
fs << "width" << itr->width;
fs << "height" << itr->height;
fs << "}";
}
fs << "]";
fs.release();
}
void ReadCvRectList(list<CvRect>& listRect)
{
listRect.clear();
FileStorage fs(SAVE_FILE_NAME, FileStorage::READ); //建立XML檔案
if (!fs.isOpened())
{
cerr << "failed to open " << SAVE_FILE_NAME << endl;
}
FileNode n = fs["VECTOR"];
if (n.type() != FileNode::SEQ)
{
cerr << "VECTOR is not a sequence! FAIL" << endl;
}
for (FileNodeIterator it = n.begin(); it != n.end(); it++)
{
CvRect rect;
rect.x = (*it)["x"];
rect.y = (*it)["y"];
rect.width = (*it)["width"];
rect.height = (*it)["height"];
listRect.push_back(rect);
}
fs.release();
}