Package pyvision :: Package types :: Module ImageBuffer :: Class ImageBuffer
[hide private]
[frames] | no frames]

Class ImageBuffer

source code

Stores a limited number of images from a video (or any other source) Makes it easy to do N-frame-differencing, for example, by easily being able to get the current (middle) frame, plus the first and last frames of the buffer. With an ImageBuffer of size N, as images are added, eventually the buffer fills, and older items are dropped off the end. This is convenient for streaming input sources, as the user can simply keep adding images to this buffer, and internally, the most recent N will be kept available.

Instance Methods [hide private]
 
__init__(self, N=5) source code
 
__getitem__(self, key) source code
 
__len__(self)
This is a fixed-sized ring buffer, so length is always the number of images that can be stored in the buffer (as initialized with Nframes)
source code
 
isFull(self) source code
 
clear(self) source code
 
getCount(self)
Note that getCount() differs from __len__() in that this method returns the number of image actually stored in the ImageBuffer, while __len__() returns the size of the buffer, defined as the number of images the buffer is allowed to store.
source code
 
getBuffer(self) source code
 
getFirst(self) source code
 
getLast(self) source code
 
getMiddle(self) source code
 
add(self, image)
add an image to the buffer, will kick out the oldest of the buffer is full
source code
 
fillBuffer(self, v)
If buffer is empty, you can use this function to spool off the first N frames of a video or list of images to initialize/fill the buffer.
source code
 
asStackBW(self, size=None)
Outputs an image buffer as a 3D numpy array ("stack") of grayscale images.
source code
 
asMontage(self, layout, tile_size=None, **kwargs) source code
 
show(self, N=10, window='Image Buffer', pos=None, delay=0) source code
Method Details [hide private]

__init__(self, N=5)
(Constructor)

source code 
Parameters:
  • N - how many image frames to buffer

add(self, image)

source code 

add an image to the buffer, will kick out the oldest of the buffer is full

Parameters:
  • image - image to add to buffer

fillBuffer(self, v)

source code 

If buffer is empty, you can use this function to spool off the first N frames of a video or list of images to initialize/fill the buffer.

Parameters:
  • v - Either a list of pv.Images, an instance of pv.Video or its subclass, or any other iterable that yields a pv.Image() when next() is called.

Note: Will cause an assertion exception if buffer is already full.

asStackBW(self, size=None)

source code 

Outputs an image buffer as a 3D numpy array ("stack") of grayscale images.

Parameters:
  • size - A tuple (w,h) indicating the output size of each frame. If None, then the size of the first image in the buffer will be used.
Returns:
a 3D array (stack) of the gray scale version of the images in the buffer. The dimensions of the stack are (N,w,h), where N is the number of images (buffer size), w and h are the width and height of each image.

show(self, N=10, window='Image Buffer', pos=None, delay=0)

source code 
Parameters:
  • N - The number of images in the buffer to display at once
  • window - The window name
  • pos - The window position
  • delay - The window display duration