使用Filestrage在OpenCV中保存和读取Mat向量的向量
我想请求使用opencv的文件存储读取和写入Mats向量向量的帮助 我使用此函数编写:使用Filestrage在OpenCV中保存和读取Mat向量的向量,opencv,vector,file-storage,Opencv,Vector,File Storage,我想请求使用opencv的文件存储读取和写入Mats向量向量的帮助 我使用此函数编写: Template<typename _Tp>inline void writeFileNodeList(FileStorage& fs, const string& name,const vector<_Tp>& items) { // typedefs //typedef typename vector<_Tp>:
Template<typename _Tp>inline void writeFileNodeList(FileStorage& fs, const string& name,const vector<_Tp>& items)
{
// typedefs
//typedef typename vector<_Tp>::const_iterator constVecIterator;
vector<Mat>::iterator it;
// write the elements in item to fs
fs << name << "[";
for (it = items.begin(); it != items.end(); ++it) {
fs << *it;
}
fs << "]";
}
Templateinline void writeFileNodeList(文件存储和fs、常量字符串和名称、常量向量和项)
{
//typedefs
//typedef typename向量::const_迭代器constvecierator;
向量::迭代器;
//将项中的元素写入fs
我终于自己解决了这个问题
代码如下:
void writeFileNodeList(FileStorage& fs, const string& name,vector<vector<Mat>> items)
{
int IDs=items.size();
// typedefs
fs << name << "{";
for (int i=0;i<IDs;i++)
{
stringstream ss;
string s;
string a;
a="ID-label";
ss << (i+1);
s = ss.str();
a+=s;
fs << a << "[";
for (int j=0;j<items[i].size();j++)
{
fs<<items[i][j];
}
fs <<"]";
}
fs << "}";
}
void writeFileNodeList(文件存储和fs、常量字符串和名称、向量项)
{
int id=items.size();
//typedefs
财政司司长
void writeFileNodeList(FileStorage& fs, const string& name,vector<vector<Mat>> items)
{
int IDs=items.size();
// typedefs
fs << name << "{";
for (int i=0;i<IDs;i++)
{
stringstream ss;
string s;
string a;
a="ID-label";
ss << (i+1);
s = ss.str();
a+=s;
fs << a << "[";
for (int j=0;j<items[i].size();j++)
{
fs<<items[i][j];
}
fs <<"]";
}
fs << "}";
}
vector<vector<Mat>> readFileNodeList2(const FileNode& fn)
{
//cout <<fn.name() <<endl;
//cout <<fn.size() <<endl;
vector<vector<Mat>> output;
//cout << fn.isMap() << endl;
for (int ID=0;ID<fn.size();ID++)
{
stringstream ss;
string s;
string a;
a="ID-label";
ss << (ID+1);
s = ss.str();
a+=s;
FileNode temp_ID;
temp_ID=fn[a];
vector<Mat> one_person_patrerns;
readFileNodeList(temp_ID,one_person_patrerns);
output.push_back(one_person_patrerns);
}
return output;
}
template<typename _Tp>inline void readFileNodeList(const FileNode& fn,vector<_Tp>& result)
{
if (fn.type() == FileNode::SEQ) {
for (FileNodeIterator it = fn.begin(); it != fn.end();) {
_Tp item;
it >> item;
result.push_back(item);
}
}
}