bool Readxml(const std::string &path)//读取
{
cv::FileStorage read_file;
read_file.open(path, cv::FileStorage::READ);//读的形式打开xml
if (!read_file.isOpened())
{
//读取失败
read_file.release();//释放
return false;
}
std::vector<std::string> key_names;
read_file["key_names"] >> key_names;
for(std::string& key_name : key_names)
{
cv::Mat value;
read_file[key_name] >> value;
m_faceDatabase[key_name] = value;
}
read_file.release();//释放
//读取成功
return true;
}
void Savexml(const std::string &path)//写入
{
cv::FileStorage write_file;
write_file.open(path, cv::FileStorage::WRITE);//以写的形式打开
std::vector<std::string> key_names;
for(const auto& item : m_faceDatabase)
{
key_names.push_back(item.first);
std::stringstream key_name;
key_name << item.first;
write_file << key_name.str() << item.second;
}
write_file << "key_names" << key_names;
write_file.release();
//保存成功
}
OpenCV读写xml
最新推荐文章于 2022-12-13 11:09:29 发布