OpenCV學習(4)——動態結構

學習一個新知識,無外乎學習它自己和它的工具。OpenCV提供許多內置的結構及處理函數,很是值得學習。node

 

內存存儲


在OpenCV中,內存存儲器是一個能夠用來存儲序列、數組和圖像的動態增加的數據結構。它由一系列的等大小的內存塊組成,是一個線性結構。數組

C++ Code
1
2
3
4
5
6
7
8
 
typedef   struct CvMemStorage
{
   
struct CvMemBlock *bottom;
   
struct CvMemBlock *top;
   
struct CvMemStorage *parent;
   
int block_size;
   
int free_space;
} CvMemStorage;

bottom指的是列首,top指的是當前指向的塊但未必是列尾。在bottom和top之間全部的塊(包括bottom, 不包括top)被徹底佔據了空間;在top和列尾之間全部的塊(包括塊尾,不包括top)則是空的;而top塊自己則被佔據了部分空間;free_space指的是top塊剩餘的空字節數。數據結構

 

C++ Code
1
2
3
4
5
 
//建立內存塊,返回指向塊頭部的指針
CvMemStorage *cvCreateMemStorage( int block_size = 0 );

//刪除內存塊
void cvReleaseMemStorage(CvMemStorage **storage);

序列 函數


稠密序列都派生自CvSeq,用來表明可擴展的一維數組―向量、棧、隊列和雙端隊列。數據間不存在空隙(即連續存放)。若是元素從序列中間被刪除或插人新的元素到序列中(不是插人到兩端),那麼此元素後邊的相關元素會被移動。工具

稀疏序列都派生自CvSet,CvSet是基於CvSeq。它們都是由結點所組成的序列,每個結點要麼被佔用要麼是空的。這些序列做爲無序的數據結構被使用,如點集、圖、哈希表等。學習

 

C++ Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
//建立一序列
CvSeq* cvCreateSeq( int seq_flags , int header_size , int elem_size , CvMenStorage* storage);

//建立序列的拷貝
CvSeq* cvCloneSeq( const CvSeq* seq , CvMenStorage* storage = NULL );

//序列逆序
CvSeq* cvSeqInvert(CvSeq* seq);

//序列排序
CvSeq* cvSeqSort(CvSeq* seq , CvCmpFunc func , void * userdata = NULL );

//序列搜索
CvSeq* cvSeqSearch(CvSeq* seq , const   void * elem , CvCmpFunc func , int is_sorted , int * elem_index , void * userdata = NULL );

//清空序列
CvSeq* cvClearSeq(CvSeq* seq );

//添加元素
CvSeq* cvSeqPush(CvSeq* seq , void * element = NULL );

//序列pop操做
CvSeq* cvSeqPop(CvSeq* seq , void * element = NULL );

//序列頭部添加元素
CvSeq* cvSeqPushFront(CvSeq* seq , void * element = NULL );

//刪除序列的頭部元素
CvSeq* cvSeqPopFront(CvSeq* seq , void * element = NULL );

//添加多個元素
CvSeq* cvSeqPushMulti(CvSeq* seq , void * element = NULL , int count , int in_front = 0 );

//刪除多個元素
CvSeq* cvSeqPopMulti(CvSeq* seq , void * element = NULL , int count , int in_front = 0 );

//添加元素到指定位置
CvSeq* cvSeqInsert(CvSeq* seq , int before_index , void * element = NULL );

//刪除指定位置元素
CvSeq* cvSeqRemove(CvSeq* seq , int index );

//返回索引位置的元素的指針
char * cvGetSeqElem( const CvSeq* seq , int index);

//將數據寫入序列
void cvStartAppendToSeq(CvSeq* seq , CvSeqWriter* writer);

//建立新序列,初始化寫入部分
void cvStartWriteSeq( int seq_flags , int header_size , int elem_size , CvMemStorage* storage , CvSeqWriter* writer);

//完成寫入操做
CvSeq* cvEndWriteSeq(CvSeqWriter* writer);

//初始化序列中的讀取過程
void cvStartReadSeq( const CvSeq* seq , CvSeqReader* reader ,  int reverse);

集合 spa


在OpenCV中,Cvset用來表明圖形、稀疏多維數組和平面子劃分等.net

 

C++ Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
//建立空的集合
CvSet* cvCreateSet( int set_flags , int header_size , int elem_size , CvMemStorage* storage);

//建立集合中的一個結點
int cvSetAdd(CvSet* set_header , CvSetElem* elem = NULL , CvSetElem** inserted_elem = NULL );

//從集合中刪除元素
void cvSetRemove(CvSet* set_header , int index);

//添加元素
CvSetElem* cvSetNew(CvSet* set_header , int index);

//刪除指針指向的元素
void cvSetRemoveByPtr(CvSet* set_header , void * elem);

//索引元素集合
CvSetElem* cvGetSetElem( const CvSet* set_header , int index);

//清空集合
void cvClearSet(CvSet* set_header);

指針


 

C++ Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
//建立圖
CvGraph* cvCreateGraph( int graph_flags , int header_size , int vtx_size , int edge_size , CvMemSorage* storage);

//插入頂點
int cvGraphAddVtx(CvGraph* graph , const CvGraphVtx* vtx = NULL , const CvGraphVtx** inserted_vtx = NULL );

//刪除一個頂點
int cvGraphRemoveVtx(CvGraph* graph , int index);

//經過指針刪除頂點
int cvGraphRemoveVtxByPrt(CvGraph* graph , CvGraphVtx* vtx);

//經過索引查找頂點
CvGraphVtx* cvGetGraphVtx(CvGraph* graph , int vtx_idx);

//返回相應的索引值
int cvGraphVtxIdx(CvGraph* graph , CvGraphVtx* vtx);

//經過索引添加邊
int cvGraphAddEdge(CvGraph* graph , int start_idx , int end_idx ,
                  
const CvGraphEdge* edge = NULL , CvGraphEdge** inserted_edge = NULL );

//經過指針添加邊
int cvGraphAddEdgeByPtr(CvGraph* graph , CvGraphVtx* start_vtx , CvGraphVtx* end_vtx ,
                       
const CvGraphEdge* edge = NULL , CvGraphEdge** inserted_edge = NULL );

//經過索引刪除邊
void cvGraphRemoveEdge(CvGraph* graph , int start_idx , int end_idx);

//經過指針刪除邊
void cvGraphRemoveEdgeByPtr(CvGraph* graph , CvGraphVtx* start_vtx , CvGraphVtx* end_vtx);

樹  orm


 

C++ Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
//初始化樹迭代器
void cvInitTreeNodeIterator(TreeNodeIterator* tree_iterator , const   void * first , int max_level);

//返回當前節點,迭代器移動到下一個節點
void * cvNextTreeNode(TreeNodeIterator* tree_iterator);

//返回當前節點,迭代器移動到前個節點
void * cvPrevTreeNode(TreeNodeIterator* tree_iterator);

//將全部節點放在序列中
CvSeq* cvTreeToNodeSeq( const   void * first , int header_size , CvMemStorage* storage);

//插入節點
void cvInsertNodeToTree( void * node , void * parent , void * frame);

//刪除節點
void cvRemoveNodeFromTree( void * node , void * frame);
相關文章
相關標籤/搜索