0

我要做的是从迭代中获取第一个矩阵,并将其保存为单独的矩阵,然后我可以使用它来对其余数据执行函数。下面是我的迭代代码;

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;

        }

有没有办法获取“pose”的第一个实例并将其保存为另一个矩阵,例如“base”?

4

1 回答 1

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(),如果您想要矩阵标题和数据的完整副本,则需要这样做。

于 2012-12-14T02:46:01.027 回答