我要做的是从迭代中取出第一个矩阵,并将其保存为单独的矩阵,然后我可以使用它来对其余数据执行函数。下面是我的迭代代码;
FileNode n = fs.root();
for (FileNodeIterator current = n.begin(); current != n.end(); current++)
{
FileNode item = *current;
Mat v, pose;
item["pose"] >> v;
string Frame;
Frame = item.name();
if (v.rows != 0) // finding the nodes that contain data and saving them as "pose"
{
transpose(v, pose);
pose.size();
cout << "The size of pose for " << Frame;
cout << " is: \n" << pose.size()<< "\n Data was collected for this frame: \n" << pose << endl;
}
if (v.rows != 6) // Nodes with no data
{
cout << "The size of pose for " << Frame;
cout << " is: \n" << v.size() << "\n No Data was collected for this frame. \n" << endl;
}
有没有办法取第一个“姿势”实例并将其保存为另一个矩阵,例如“base”?
答案 0 :(得分:0)
如果我理解正确,也许您想要的是声明一个标志,您可以使用它来保存矩阵的第一个实例,如下所示:
FileNode n = fs.root();
bool firstTime = true;
Mat base;
for (FileNodeIterator current = n.begin(); current != n.end(); current++)
{
FileNode item = *current;
Mat v, pose;
item["pose"] >> v;
string Frame;
Frame = item.name();
if (v.rows != 0) // finding the nodes that contain data and saving them as "pose"
{
transpose(v, pose);
pose.size();
cout << "The size of pose for " << Frame;
cout << " is: \n" << pose.size()<< "\n Data was collected for this frame: \n" << pose << endl;
}
if (v.rows != 6) // Nodes with no data
{
cout << "The size of pose for " << Frame;
cout << " is: \n" << v.size() << "\n No Data was collected for this frame. \n" << endl;
}
if(firstTime)
{
base = pose.clone();
firstTime = false;
}
}
请注意clone()
,如果您需要矩阵标头和数据的完整副本,则需要这样做。