Usage of cvseq in opencv

Source: Internet
Author: User
Usage of cvseq in opencv

Function prototype Description
Cvseq *
Cvcreateseq (INT seq_flags, int header_size, int elem_size, cvmemstorage *
Storage)
Function: Creates a sequence.

Parameter: seq_flags indicates the sequence symbol. If the sequence is not passed to any function that uses a specific sequence, set it to 0. Otherwise, select an appropriate type from the predefined sequence type.
Header_size is the size of the sequence header. It must be greater than or equal to sizeof (cvseq ). If a type or its extension is specified, this type must be suitable for the header size of the base class.
Elem_size is the size of the element, in bytes. The size must be consistent with the sequence type (specified by seq_flags. For example, for the sequence of a vertex, the element type
Cv_seq_eltype_point should be specified. The elem_size parameter must be equivalent to sizeof (cvpoint ). Storage refers to
Memory

Cvseq *
Cvcloneseq (const cvseq * seq, cvmemstorage * storage = NULL)
Function: Creates a copy of a sequence.
Void
Cvseqinvert (cvseq * SEQ)
Function: Performs reverse operations on the elements in the sequence.
Void
Cvseqsort (cvseq * seq, cvcmpfunc func, void * userdata = NULL)

Function: uses a specific comparison function to sort the elements in a sequence.

Char *
Cvseqsearch (cvseq * seq, const void * ELEM, cvcmpfunc func, int is_sorted, int
* Elem_idx, void * userdata = NULL)
Function: query the elements in a sequence.
Void
Cvclearseq (cvseq * SEQ );
Function: clears a sequence.
Char *
Cvseqpush (cvseq * seq, void * element = NULL)
Function: add elements to the end of a sequence.

Void cvseqpop (cvseq * seq, void * element = NULL)

Function: deletes the tail element of a sequence.

Char * cvseqpushfront (cvseq * seq, void * element = NULL)

Function: adds an element to the sequence header.

Void cvseqpopfront (cvseq * seq, void * element = NULL)

Function: delete an element in the sequence header.

Void cvseqpushmulti (cvseq * seq, void * elements, int
Count, int in_front = 0 );

Function: adds multiple elements to the end or header of a sequence.

Void cvseqpopmulti (cvseq * seq, void * elements, int
Count, int in_front = 0)

Function: deletes multiple sequence headers or tail elements.

Char * cvseqinsert (cvseq * seq, int before_index, void *
Element = NULL)

Function: adds an element at a specified position in the sequence.

Void cvseqremove (cvseq * seq, int index)

Function: deletes an element at a specified position in the sequence.

Char * cvgetseqelem (const cvseq * seq, int index)

Function: returns the element pointer specified by the index.

Int cvseqelemidx (const cvseq * seq, const void *
Element, cvseqblock ** block = NULL)

Function: returns the index of the element in the sequence.

Void cvstartappendtoseq (cvseq * seq, cvseqwriter *
Writer)

Function: writes data to the sequence and initializes the process.

Void cvstartwriteseq (INT seq_flags, int
Header_size, int elem_size, cvmemstorage * storage, cvseqwriter * writer)

Function: Create a new sequence and initialize the write part.

Cvseq * cvendwriteseq (cvseqwriter * writer)

Function: completes write operations.

Void cvstartreadseq (const cvseq * seq, cvseqreader *
Reader, int reverse = 0)

Function: Initialize the reading process in the sequence.

 

 

Discussion on the internal structure of opencv cvseq

I am always confused about what cvseq is like, because I used to get a function library written by someone else, and its return value is a cvseq pointer. My task is to traverse all sequence. However
And then delete the sequence that does not meet the requirements. Since there is no document, I didn't know whether to traverse the elements in sequence or sequence. So I
Write the following code:
Cvseq * pcurseq = pinputseq; <br/> int Index = 0; <br/> while (pcurseq = pcurseq-> h_next) <br/>{< br/> If (process (pcurseq) <br/>{< br/> pcurseq = pcurseq-> h_prev; // For the sake of simplicity, do not consider whether the list header is <br/> cvseqremove (pinputseq, index); <br/> -- index; <br/>}< br/> + + index; <br/>}


It turns out that this code is incorrect, and the error message is often returned
>
Opencv error: One of arguments 'values is out of range
(Invalid index)


>


In function cvseqremove, cxdatastructs. cpp (1587)




Is
What will happen? Let's take a look at the source code of cvseq. The following is the definition of cvseq in opencv2.0.
# Define cv_tree_node_fields (node_type)/<br/> int flags;/* micsellaneous flags * // <br/> int header_size; /* size of sequence header * // <br/> struct node_type * h_prev;/* previous sequence * // <br/> struct node_type * h_next; /* next sequence * // <br/> struct node_type * v_prev; /* 2nd previous sequence * // <br/> struct node_type * v_next/* 2nd next sequence */<br/>/* <br/> read/write sequence. <br/> elements can be dynamically inserted to or deleted from the sequence. <br/> */<br/> # define cv_sequence_fields ()/<br/> cv_tree_node_fields (cvseq);/<br/> int total; /* Total number of elements * // <br/> int elem_size;/* size of sequence element in bytes * // <br/> char * block_max; /* maximal bound of the last block * // <br/> char * PTR;/* Current write pointer * // <br/> int delta_elems; /* How many elements allocated when the seq grows * // <br/> cvmemstorage * storage;/* Where the seq is stored * // <br/> cvseqblock * free_blocks; /* free blocks list * // <br/> cvseqblock * first; /* pointer to the first sequence block */<br/> typedef struct cvseq <br/>{< br/> cv_sequence_fields () <br/>}< br/> cvseq; <br/>


Originally, cvseq itself is a scalable sequence. cvseq: Total refers to the number of valid elements in the sequence. h_next and h_prev do not point to the internal element of cvseq.
And point to other cvseq. Return to the original code of the Article. We can see that the Code has a logical error. First, the while statement traverses all cvseq and uses
Process processes each cvseq. When cvseq needs to be deleted, cvseqremove is used to delete the index element in the current cvseq. Actually
At this time, the index is likely to exceed the total number of elements in the current cvseq, so an error occurs that exceeds the boundary. The correct method is to directly Delete the cvseq.
Cvseq * pcurseq = pinputseq; <br/> cvseq * poldseq = NULL; <br/> while (pcurseq) <br/>{< br/> If (process (pcurseq )) <br/>{< br/> poldseq = pcurseq; <br/> If (poldseq-> h_prev) <br/>{< br/> pcurseq = poldseq-> h_prev; <br/> pcurseq-> h_next = poldseq-> h_next; <br/> poldseq-> h_next-> h_prev = pcurseq; <br/> pcurseq = pcurseq-> h_next; <br/> cvclearseq (poldseq); <br/>}< br/> else <br/>{< br/> pcurseq = poldseq-> h_next; <br/> pcurseq-> h_prev = NULL; <br/> cvclearseq (poldseq ); <br/>}< br/> else <br/> {<br/> pcurseq = pcurseq-> h_next; <br/>}< br/>}

Later, I checked in Google book and found that learning opencv: computer vision with the opencv
The following is a good description in Library:
The sequence structure itself has some important
Elements that you shoshould be aware of. The first, and one you will
Use often, is total
. This is
Total number of points or objects in the sequence. The next four important
Elements are pointers to other sequence: h_prev
, H_next
, V_prev
And v_next
. These four pointers are part of what are called cv_tree_node_fields
; They are used
Not to indicate elements inside of the sequence but rather to connect
Different sequences to one another. Other objects in the opencv
Universe also contain these tree node fields.

 

Reference: http://hi.baidu.com/ltbing/blog/item/490d88948af27c14d21b7008.html

Http://jackchongsun.blog.163.com/blog/static/4071607201019101312221/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.