CvMemStorage,CvSeq,CvContour和cvFindContour的分析

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 );
只要将查找到的第一个轮廓存入创建的树的结点,便可利用指针找到其他的结点,找到的轮廓是点集,而非封闭的曲线。





  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值