Reputation: 35
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?
Upvotes: 2
Views: 342
Reputation: 172
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();
Upvotes: 1