CvSeq源码
#define CV_TREE_NODE_FIELDS(node_type) /
int flags; /* micsellaneous flags */ /
int header_size; /* size of sequence header */ /
struct node_type* h_prev; /* previous sequence */ /
struct node_type* h_next; /* next sequence */ /
struct node_type* v_prev; /* 2nd previous sequence */ /
struct node_type* v_next /* 2nd next sequence */
/*
Read/Write sequence.
Elements can be dynamically inserted to or deleted from the sequence.
*/
#define CV_SEQUENCE_FIELDS() /
CV_TREE_NODE_FIELDS(CvSeq); /
int total; /* total number of elements */ /
int elem_size; /* size of sequence element in bytes */ /
char* block_max; /* maximal bound of the last block */ /
char* ptr; /* current write pointer */ /
int delta_elems; /* how many elements allocated when the seq grows */ /
CvMemStorage* storage; /* where the seq is stored */ /
CvSeqBlock* free_blocks; /* free blocks list */ /
CvSeqBlock* first; /* pointer to the first sequence block */
typedef struct CvSeq
{
CV_SEQUENCE_FIELDS()
}
CvSeq;
CvSeq本身就是可动态增长序列,创建一个CvSeq需要先申请一块儿空间,需要用到CvMemStorage(动态内存存储及操作)
CvMemStorage
typedef struct CvMemStorage
{
struct CvMemBlock* bottom;/* first allocated block */
struct CvMemBlock* top; /* the current memory block - top of the stack */
struct CvMemStorage* parent; /* borrows new blocks from */
int block_size; /* block size */
int free_space; /* free space in the top block (in bytes) */
} CvMemStorage;
关于这个数据结构,有一篇博客讲的非常清楚
http://blog.csdn.net/myeclipseworkspace/article/details/6299281
用完之后要手动释放,否则可能会内存泄露,cvClearMemStorage(storage);
我得理解,cvCreateSeq(int seq_flags,int header_size,int elem_size,CvMemStorage* storage)函数根据参数设定的大小,创建了一个序列,这个序列是树上的一个节点,可动态增加。
CvContour发展自序列
typedef struct CvContour
{
CV_CONTOUR_FIELDS()
}
CvContour;
#define CV_CONTOUR_FIELDS ( )
Value:
CV_SEQUENCE_FIELDS() \
CvRect rect; \
int color; \
int reserved[3];
cvFindContours
int iCount=cvFindContours( imgDst, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_CODE );
只要将查找到的第一个轮廓存入创建的树的结点,便可利用指针找到其他的结点,找到的轮廓是点集,而非封闭的曲线。