I have a yml file and i want to open the file for reading using the existing opencv 1.0 functions. The file contains something like this:
%YAML:1.0
Image file: "00961010.jpg"
Contours count: 8
Contours:
-
Name: FO
Count: 41
Closed: 0
Points:
-
x: 740.7766113281250000
y: 853.0124511718750000
-
x: 745.1353149414062500
y: 875.5324096679687500
Can you please provide some example of how to iterate over this data? I need only the x, y points and store then in an array. I have searched but i did not found a similar example 开发者_Python百科of data and please help me. Thanks in advance!
You're going to want to look at the cvFileStorage data-structures, and functions.
Here is an example from OpenCV to get you started:
#include "cxcore.h"
int main( int argc, char** argv )
{
CvFileStorage* fs = cvOpenFileStorage( "points.yml", 0, CV_STORAGE_READ );
CvStringHashNode* x_key = cvGetHashedNode( fs, "x", -1, 1 );
CvStringHashNode* y_key = cvGetHashedNode( fs, "y", -1, 1 );
CvFileNode* points = cvGetFileNodeByName( fs, 0, "points" );
if( CV_NODE_IS_SEQ(points->tag) )
{
CvSeq* seq = points->data.seq;
int i, total = seq->total;
CvSeqReader reader;
cvStartReadSeq( seq, &reader, 0 );
for( i = 0; i < total; i++ )
{
CvFileNode* pt = (CvFileNode*)reader.ptr;
int x = cvReadIntByName( fs, pt, "x", 0 /* default value */ );
int y = cvReadIntByName( fs, pt, "y", 0 /* default value */ );
CV_NEXT_SEQ_ELEM( seq->elem_size, reader );
printf("point%d is (x = %d, y = %d)\n", i, x, y);
}
}
cvReleaseFileStorage( &fs );
return 0;
}
精彩评论