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;
/* Creates new empty sequence that will reside in the specified storage */
CVAPI(CvSeq*) cvCreateSeq( int seq_flags, int header_size,
int elem_size, CvMemStorage* storage );
创建序列:header_size 序列的头大小 一般为sizeof(CvSeq) 除使用CV_SEQUENCE_FIELDS()扩展时,按扩展后大小
elem_size 序列存储元素大小
storage 为序列指定内存存储器
seq_flags 由3个类值组成 1元素类型2序列性质(集合、曲线、二叉树、图)3序列其它属性(闭合、简单、凸、嵌套)
/* Removes all the elements from the sequence. The freed memory
can be reused later only by the same sequence unless cvClearMemStorage
or cvRestoreMemStoragePos is called */
CVAPI(void) cvClearSeq( CvSeq* seq );清空序列中所有元素。内存返还内存存储器,不返还系统。
/* Retrives pointer to specified sequence element.
Negative indices are supported and mean counting from the end
(e.g -1 means the last sequence element) */
CVAPI(char*) cvGetSeqElem( const CvSeq* seq, int index );访问指定元素
/* Calculates index of the specified sequence element.
Returns -1 if element does not belong to the sequence */
CVAPI(int) cvSeqElemIdx( const CvSeq* seq, const void* element,
CvSeqBlock** block CV_DEFAULT(NULL) );
检测元素是否在序列中,若block不空,返回该元素地址:该函数并非查询序列中内容相同的元素,而是查找元素的位置是否在序列中。
CV_INLINE CvSeq* cvCloneSeq( const CvSeq* seq, CvMemStorage* storage CV_DEFAULT(NULL))
{
return cvSeqSlice( seq, CV_WHOLE_SEQ, storage, 1 );
}
复制一个序列,对cvSeqSlice的简单封装。
/* Extracts sequence slice (with or without copying sequence elements) */
CVAPI(CvSeq*) cvSeqSlice( const CvSeq* seq, CvSlice slice,
CvMemStorage* storage CV_DEFAULT(NULL),
int copy_data CV_DEFAULT(0));