readseq.cpp
上传用户:banwdc
上传日期:2016-06-25
资源大小:2871k
文件大小:2k
- #include <stdio.h>
- #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;
- #if 1 /* 快变量 */
- CvFileNode* xnode = cvGetFileNode( fs, pt, x_key, 0 );
- CvFileNode* ynode = cvGetFileNode( fs, pt, y_key, 0 );
- assert( xnode && CV_NODE_IS_INT(xnode->tag) &&
- ynode && CV_NODE_IS_INT(ynode->tag));
- int x = xnode->data.i; // or x = cvReadInt( xnode, 0 );
- int y = ynode->data.i; // or y = cvReadInt( ynode, 0 );
- #elif 1 /* 慢变量:不使用x值与y值 */
- CvFileNode* xnode = cvGetFileNodeByName( fs, pt, "x" );
- CvFileNode* ynode = cvGetFileNodeByName( fs, pt, "y" );
- assert( xnode && CV_NODE_IS_INT(xnode->tag) &&
- ynode && CV_NODE_IS_INT(ynode->tag));
- int x = xnode->data.i; // or x = cvReadInt( xnode, 0 );
- int y = ynode->data.i; // or y = cvReadInt( ynode, 0 );
- #else /* 最慢的可以轻松使用的变量 */
- int x = cvReadIntByName( fs, pt, "x", 0 /* default value */ );
- int y = cvReadIntByName( fs, pt, "y", 0 /* default value */ );
- #endif
- CV_NEXT_SEQ_ELEM( seq->elem_size, reader );
- printf("%d: (%d, %d)n", i, x, y );
- }
- }
- cvReleaseFileStorage( &fs );
- return 0;
- }