我正在使用OpenCV 2.4.2 FileStorage,并试图存储一个矢量向量的方式,我可以读回来。什么是最好的方式做这个?OpenCV存储矢量向量的点矢量<vector <Point>>
下面是我试过,但读它放回引发错误: OpenCV Error: Unspecified error (The sequence element is not a numerical scalar) in cvReadRawDataSlice, file /Downloads/OpenCV-2.4.2/modules/core/src/persistence.cpp, line 3367
节能:
bool writeVectorVectorPoint(string fname, vector<vector<Point> > vvP)
{
FileStorage fs(fname, FileStorage::WRITE);
fs << "nV" << static_cast<int>(vvP.size());
for(size_t i = 0; i < vvP.size(); i++)
{
ostringstream istr;
istr << "v" << i;
fs << istr.str() << "[";
for(size_t jj = 0; jj < vvP.at(i).size(); jj++)
{
ostringstream jjstr;
fs << vvP.at(i).at(jj);
}
fs << "]";
}
fs.release();
return(true);
}
阅读:
FileStorage fs(argv[2], FileStorage::READ);
if(!fs.isOpened())
{
cout << "Unable to open: " << argv[2] << endl;
return(-1);
}
int nV = static_cast<int>(fs["nV"]);
cout << "nV: " << nV << endl;
vector<Point> vPts;
for(int ii = 0; ii < nV; ii++)
{
ostringstream iistr;
iistr << "v" << ii;
cout << iistr.str() << ": ";
fs[iistr.str()] >> vPts;
cout << endl;
}
fs.release();
的xml文件看起来像:
<?xml version="1.0"?>
<opencv_storage>
<nV>4</nV>
<v0>
<_>
269 490</_>
<_>
400 522</_>
<_>
331 600</_>
<_>
294 610</_></v0>
<v1>
<_>
537 510</_>
<_>
590 458</_>
<_>
603 612</_>
<_>
508 626</_></v1>
<v2>
<_>
594 287</_>
<_>
444 240</_></v2>
<v3>
<_>
451 330</_>
<_>
632 342</_>
<_>
652 344</_>
<_>
470 381</_></v3>
</opencv_storage>
的readVectorOfVector函数的第一个参数应该是FileStorage&FS基于bloublo
IM的答案读矢量o关键点和垫,而不是FileNode&fns,对吗?然后读取节点将是:FileNode fn = fs [name]; – 2015-06-22 17:42:52