c++ - 在第二个节点解析嵌套的 yml 文件

标签 c++ opencv yaml

我有以下 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);
}

我走到 Contours 去计数,迭代它们,并找到总和,但我被困在点节点上。我如何解析这个节点?

最佳答案

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();

关于c++ - 在第二个节点解析嵌套的 yml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7940216/

相关文章:

c++ - 我不明白这个功能是如何工作的

c++ - c++ 可变关键字对线程有害吗?

c++ - 仅用于 SELECT 语句的 SQL 引擎 - C++ 中的手写解析器

c++ - Opencv cpp 使用多线程处理同一视频的不同部分

amazon-web-services - AWS 上的 CloudFormation 模板错误

c++ - 在 send() 中可以放置标志 MSG_NOSIGNAL 吗?

python - 在python中读取预处理的cr2 RAW图像数据

opencv - 基于密度的图像-Opencv 热图

amazon-web-services - 从 Codecommit 源代码构建 AWS 跨账户管道

python - 为什么 PyYAML 花费这么多时间来解析 YAML 文件?