解析第二个节点的嵌套 yml 文件

发布于 2024-12-12 10:51:12 字数 869 浏览 2 评论 0原文

我有以下 yml 文件:

     Contours count: 8
     Contours:
             -
           Name: MI
           Count: 28
           Points:
               -
               x: 1116.
               y: 687.
               -
               x: 1.1224088134765625e+003
               y: 680.5911865234375000
               -

我有以下 C++ 代码,在 Qt 和 opencv 2.3.1 下:

cv::FileNode Points = fs["Contours"];
if (Points.type() != cv::FileNode::SEQ)
    ui->textEdit->append("is not a sequence! FAIL");
cv::FileNodeIterator it = Points.begin(), it_end = Points.end();
int idx = 0; int Count = 0;
std::vector<uchar> lbpval;
for( ; it != it_end; ++it, idx++ )
{
    Count += (int)(*it)["Count"];
    QString s = QString::number(Count);
    ui->textEdit->append(s);
}

我一直走到轮廓转到计数,迭代它们,并找到总和,但我卡在了点节点。我该如何解析这个节点?

I have the following yml file:

     Contours count: 8
     Contours:
             -
           Name: MI
           Count: 28
           Points:
               -
               x: 1116.
               y: 687.
               -
               x: 1.1224088134765625e+003
               y: 680.5911865234375000
               -

I have the following c++ code, under Qt, and opencv 2.3.1:

cv::FileNode Points = fs["Contours"];
if (Points.type() != cv::FileNode::SEQ)
    ui->textEdit->append("is not a sequence! FAIL");
cv::FileNodeIterator it = Points.begin(), it_end = Points.end();
int idx = 0; int Count = 0;
std::vector<uchar> lbpval;
for( ; it != it_end; ++it, idx++ )
{
    Count += (int)(*it)["Count"];
    QString s = QString::number(Count);
    ui->textEdit->append(s);
}

I walk until Contours go to Count, iterate them, and find the total sum, but i am stuck at the Points node. How can i parse this node?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡墨 2024-12-19 10:51:12
for( ; it != it_end; ++it, idx++ )
{
    Count += (int)(*it)["Count"];
    QString s = QString::number(Count);
    ui->textEdit->append("Count: "+s);
    ui->textEdit->append("-");
    cv::FileNode Points = (*it)["Points"];
    cv::FileNodeIterator it = Points.begin(), it_end = Points.end();
    int idx = 0; int x = 0; int y = 0;
    for( ; it != it_end; ++it, idx++ )
    {
        x = (int)(*it)["x"];
        y = (int)(*it)["y"];
        points_xy.x = x; points_xy.y = y;
        QString s = QString::number(x);
        QString t = QString::number(y);
        ui->textEdit->append("x: "+s);
        ui->textEdit->append("y: "+t);
        ui->textEdit->append("-");
    }
}
fs.release();
for( ; it != it_end; ++it, idx++ )
{
    Count += (int)(*it)["Count"];
    QString s = QString::number(Count);
    ui->textEdit->append("Count: "+s);
    ui->textEdit->append("-");
    cv::FileNode Points = (*it)["Points"];
    cv::FileNodeIterator it = Points.begin(), it_end = Points.end();
    int idx = 0; int x = 0; int y = 0;
    for( ; it != it_end; ++it, idx++ )
    {
        x = (int)(*it)["x"];
        y = (int)(*it)["y"];
        points_xy.x = x; points_xy.y = y;
        QString s = QString::number(x);
        QString t = QString::number(y);
        ui->textEdit->append("x: "+s);
        ui->textEdit->append("y: "+t);
        ui->textEdit->append("-");
    }
}
fs.release();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文