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
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 .
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)
Creates a copy of a sequence.
Parameters: |
|
---|
The function makes a complete copy of the input sequence and returns it.
Creates memory storage.
Parameter: | 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.
The function reverses the sequence in-place - makes the first element go last, the last element go first and so forth.
Removes an element from the middle of a sequence.
Parameters: |
|
---|
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.