Dynamic Structures


Comments from the Wiki

class CvMemStorage

Growing memory storage.

Many OpenCV functions use a given storage area for their results and working storage. These storage areas can be created using CreateMemStorage . OpenCV Python tracks the objects occupying a CvMemStorage, and automatically releases the CvMemStorage when there are no objects referring to it. For this reason, there is explicit function to release a CvMemStorage.

>>> import cv
>>> image = cv.LoadImageM("building.jpg", cv.CV_LOAD_IMAGE_GRAYSCALE)
>>> seq = cv.FindContours(image, cv.CreateMemStorage(), cv.CV_RETR_TREE, cv.CV_CHAIN_APPROX_SIMPLE)
>>> del seq   # associated storage is also released


Comments from the Wiki

class CvSeq

Growable sequence of elements.

Many OpenCV functions return a CvSeq object. The CvSeq obect is a sequence, so these are all legal:

seq = cv.FindContours(scribble, storage, cv.CV_RETR_CCOMP, cv.CV_CHAIN_APPROX_SIMPLE)
# seq is a sequence of point pairs
print len(seq)
# FindContours returns a sequence of (x,y) points, so to print them out:
for (x,y) in seq:
   print (x,y)
print seq[10]            # tenth entry in the seqeuence
print seq[::-1]          # reversed sequence
print sorted(list(seq))  # sorted sequence

Also, a CvSeq object has methods h_next() , h_prev() , v_next() and v_prev() . Some OpenCV functions (for example FindContours ) can return multiple CvSeq objects, connected by these relations. In this case the methods return the other sequences. If no relation between sequences exists, then the methods return None .


Comments from the Wiki

class CvSet

Collection of nodes.

Some OpenCV functions return a CvSet object. The CvSet obect is iterable, for example:

for i in s:
  print i
print set(s)
print list(s)


Comments from the Wiki

CloneSeq(seq, storage) → None

Creates a copy of a sequence.

  • seq (CvSeq) – Sequence
  • storage (CvMemStorage) – The destination storage block to hold the new sequence header and the copied data, if any. If it is NULL, the function uses the storage block containing the input sequence.

The function makes a complete copy of the input sequence and returns it.


Comments from the Wiki

CreateMemStorage(blockSize = 0) → memstorage

Creates memory storage.

Parameters:blockSize (int) – Size of the storage blocks in bytes. If it is 0, the block size is set to a default value - currently it is about 64K.

The function creates an empty memory storage. See CvMemStorage description.


Comments from the Wiki

SeqInvert(seq) → None

Reverses the order of sequence elements.

Parameters:seq (CvSeq) – Sequence

The function reverses the sequence in-place - makes the first element go last, the last element go first and so forth.


Comments from the Wiki

SeqRemove(seq, index) → None

Removes an element from the middle of a sequence.

  • seq (CvSeq) – Sequence
  • index (int) – Index of removed element

The function removes elements with the given index. If the index is out of range the function reports an error. An attempt to remove an element from an empty sequence is a special case of this situation. The function removes an element by shifting the sequence elements between the nearest end of the sequence and the index -th position, not counting the latter.


Comments from the Wiki

SeqRemoveSlice(seq, slice) → None

Removes a sequence slice.

  • seq (CvSeq) – Sequence
  • slice (CvSlice) – The part of the sequence to remove

The function removes a slice from the sequence.

Table Of Contents

Previous topic

Operations on Arrays

Next topic

Drawing Functions

This Page