FilterBankGenerator Class Reference#include <FilterBankGenerator.h>
Inheritance diagram for FilterBankGenerator:
[legend]List of all members.
Detailed Description
Abstract base class for generators of FilterBankEvent's.
This is needed to provide an interface for the FilterBankEvent to call back when the actual image data is requested from it. This facilitates lazy calculation of image data... no sense in processing layers or channels which aren't actually going to be used...
Also this way we save on allocating/deallocating large memory blocks on each event... the buffers allocated here can be reused frame to frame.
Larger layer indicies generally indicate higher resolution images in a scaling pyramid, but you are free to store your own data however you wish.
Serialization Format
First, be sure to get a good overview of the LoadSave style. Most serialization is handled using this interface.
When, for instance, RawCameraGenerator::SaveBuffer() is called, it first calls it's super class, FilterBankGenerator::SaveBuffer(), which will write out the general image information, common to all subclasses of FilterBankGenerator. (i'll cover the specifics in a second) Once that's done, the RawCameraGenerator adds it's own bit of header and then saves the image data itself.
Note that only a single channel is being saved at this point. So for instance, all the Y information. No interleaving is going on. (unless you're saving from InterleavedYUVGenerator of course, which treats the 3 interleaved channels as a single image) Otherwise,only one image (selected with selectSaveImage()) of the bank will loaded or saved at a time.
So, anyway. The first header will be the same for all FilterBankGenerator subclasses. In the specification below, I'm going to use one field per line (the new lines are not literal, it's a binary stream). Each field is of the form '<type:name> (notes)'
FilterBankGenerator Header: (from FilterBankGenerator::SaveBuffer())
- <
string: "FbkImage"> (remember a 'string' is len+str+0; so this is the literal "\010\0\0\0FbkImage\0"; also remember "\010" is octal for 8) - <
unsigned int: width> - <
unsigned int: height> - <
unsigned int: image layer> - <
unsigned int: image channel> (so notice you can tell which channel it is after it's been saved)
Generator Specific Header (selected examples follow, or similarly, any of the other generators)
- RawCameraGenerator: (from RawCameraGenerator::SaveBuffer())
- <
string: "RawImage"> - <
char[width*height]: image data> (note, just once channel being stored)
- InterleavedYUVGenerator: (from InterleavedYUVGenerator::SaveBuffer())
- <
string: "InterleavedYUVImage"> - <
char[width*height*3]: image data> (in YVU order, technically YCbCr)
- SegmentedColorGenerator: (from SegmentedColorGenerator::SaveBuffer())
- <
string: "SegColorImage"> - <
char[width*height]: image data> (one byte per sample) - <
unsigned int: num_cols> (number of different colors available) - for each of num_col:
- <
char: red> red color to use for display of this index - <
char: green> green color to use for display of this index - <
char: blue> blue color to use for display of this index
- RLEGenerator: (from RLEGenerator::SaveBuffer())
- <
string: "RLEImage"> (remember a 'string' is len+str+0; so this is the literal "\010\0\0\0RLEImage\0"; also remember "\010" is octal for 8) - <
unsigned int: num_runs> (how many runs will follow) - for each of num_runs:
- <
char: color> (index value of color of run) - <
short: x> (x position of start of run ("unknown" runs are skipped - assume index 0 for pixels which are jumped)) - <
short: width> (length of run, will not exceed remaining width of image)
- notice there's no color information from RLE - it's not (shouldn't be) assuming anything about the data being compressed)
However, while we're on the topic, I'll mention that although this is the same image format used for streaming to VisionGUI, there's a few more fields added by RawCamBehavior or SegCamBehavior at the beginning of each packet. See those classes for more information on the wireless protocol. That should tell you everything you need to know to interpret the vision stream as well.
Adding New FilterBankGenerator Subclasses
If you're doing fancy memory stuff, you probably want to override the freeCaches() and destruct() functions so that the default implementation won't try to free something it shouldn't. Don't forget to call them from your own destructor though, otherwise your versions won't get called before the default implementation's does.
If you want to be able to transmit or save your images, you will need to override the LoadSave functions (listed below) to provide your own code for interpreting the image data itself, and then create or modify a behavior to open a socket and transmit the information. (you could do that from within the generator itself if you like)
You will probably also want to add a few extra functions to allow users to set compression/data format parameters.
- See also:
- RawCameraGenerator, SegmentedColorGenerator for the basic image access
RLEGenerator, RegionGenerator for some relatively simple examples of vision stages if you want to make some of your own.
Definition at line 112 of file FilterBankGenerator.h.
|
Public Member Functions |
| | FilterBankGenerator () |
| | constructor, calls setNumImages(1,1)
|
| | FilterBankGenerator (unsigned int layers, unsigned int channels) |
| | constructor
|
| | FilterBankGenerator (const std::string &name, unsigned int layers, unsigned int channels, EventBase::EventGeneratorID_t srcgid, unsigned int srcsid, EventBase::EventGeneratorID_t mgid, unsigned int msid) |
| | constructor
|
| | ~FilterBankGenerator () |
| | destructor
|
| virtual unsigned int | getNumLayers () const |
| | returns the number of image layers (e.g. different resolutions available)
|
| virtual unsigned int | getNumChannels () const |
| | returns the number of channels per image (e.g. Y, U, or V components)
|
| virtual unsigned char * | getImage (unsigned int layer, unsigned int channel) const |
| | returns pointer to the beginning of the image data for the specified layer and channel
|
| unsigned int | getWidth (unsigned int layer) const |
| | returns width (in samples) of the image in a given layer
|
| unsigned int | getHeight (unsigned int layer) const |
| | returns height (in samples) of the image in a given layer
|
| unsigned int | getSkip (unsigned int layer) const |
| | returns the bytes to skip from the one-past-end of a row to get the beginning of the next
|
| unsigned int | getStride (unsigned int layer) const |
| | returns the bytes to skip from the beginning of one row to get the beginning of the next
|
| unsigned int | getIncrement (unsigned int layer) const |
| | returns the increment (in bytes) to use to go from one sample to the next
|
| unsigned int | getFrameNumber () const |
| | returns the frame number of the current frame, see frameNumber
|
| unsigned int | getFramesProcessed () const |
| | returns the number of frames processed, see framesProcessed
|
| virtual void | freeCaches () |
| | deletes storage of cached images and marks it invalid
|
| virtual void | invalidateCaches () |
| | marks all of the cached images as invalid (but doesn't free their memory)
|
| virtual void | processEvent (const EventBase &) |
| | default implementation ignore events, just so you don't have to define it if you don't receive events
|
|
| virtual unsigned int | getBinSize () const |
| | calculates space needed to save - if you can't precisely add up the size, overestimate and things will still work.
|
| virtual unsigned int | LoadBuffer (const char buf[], unsigned int len) |
| virtual unsigned int | SaveBuffer (char buf[], unsigned int len) const |
| | Save to a given buffer.
|
| virtual void | selectSaveImage (unsigned int layer, unsigned int channel) |
| | not actually part of the LoadSave interface, but allows you to select which image of the bank will be saved
|
| virtual unsigned int | getSelectedSaveLayer () const |
| | returns layer to be saved, or layer of last image loaded
|
| virtual unsigned int | getSelectedSaveChannel () const |
| | returns channel to be saved, or channel of last image loaded
|
Protected Member Functions |
| virtual void | setNumImages (unsigned int nLayers, unsigned int nChannels) |
| | resizes the filter bank information storage area, you should override this to do your setup and call it from your constructor
|
| virtual unsigned char * | createImageCache (unsigned int layer, unsigned int channel) const=0 |
| | create new image data storage area for the cache - this called by getImage() only when the corresponding entry in images is NULL
|
| virtual void | calcImage (unsigned int layer, unsigned int channel) const=0 |
| | should calculate new image data, called by getImage() only when imageValids indicates the image being requested is dirty (and only after getImage() has already called createImageCache())
|
| virtual void | destruct () |
| | deletes the arrays
|
Protected Attributes |
| unsigned int | numLayers |
| | current number of layers available
|
| unsigned int | numChannels |
| | current number of channels available
|
| unsigned int * | widths |
| | an array of size numLayers, width (in samples) in pixels of each layer
|
| unsigned int * | heights |
| | an array of size numLayers, height (in samples) in pixels of each layer
|
| unsigned int * | skips |
| | an array of size numLayers, skip (in bytes) from row end to next row begin
|
| unsigned int * | strides |
| | an array of size numLayers, stride (in bytes) from a given column in one row to the same column in the next row
|
| unsigned int * | increments |
| | an array of size numLayers, increment (in bytes) to use to get from one sample to the next
|
| unsigned char *** | images |
| | an array [numLayers][numChannels], stores pointer to cached image data
|
| bool ** | imageValids |
| | an array [numLayers][numChannels], entry is true if cached data is still valid
|
| unsigned int | selectedSaveLayer |
| | layer to be manipulated with the LoadSave functions
|
| unsigned int | selectedSaveChannel |
| | channel to be manipulated with the LoadSave functions
|
| unsigned int | frameNumber |
| | the current frame number - subclasses will need to set to the source's frameNumber when they receive a new frame (probably from processEvent())
|
| unsigned int | framesProcessed |
| | subclasses should increment this any time they make a new filter bank available (probably by throwing an event)
|
Private Member Functions |
| | FilterBankGenerator (const FilterBankGenerator &fbk) |
| | don't call
|
| const FilterBankGenerator & | operator= (const FilterBankGenerator &fbk) |
| | don't call
|
Constructor & Destructor Documentation
| FilterBankGenerator::FilterBankGenerator |
( |
|
) |
[inline] |
|
| FilterBankGenerator::FilterBankGenerator |
( |
unsigned int |
layers, |
|
|
unsigned int |
channels |
|
) |
[inline] |
|
Member Function Documentation
| virtual void FilterBankGenerator::calcImage |
( |
unsigned int |
layer, |
|
|
unsigned int |
channel |
|
) |
const [protected, pure virtual] |
|
| virtual unsigned char* FilterBankGenerator::createImageCache |
( |
unsigned int |
layer, |
|
|
unsigned int |
channel |
|
) |
const [protected, pure virtual] |
|
| void FilterBankGenerator::destruct |
( |
|
) |
[protected, virtual] |
|
|
|
deletes the arrays
Reimplemented in CDTGenerator, JPEGGenerator, RawCameraGenerator, RegionGenerator, and RLEGenerator.
Definition at line 106 of file FilterBankGenerator.cc.
Referenced by RLEGenerator::destruct(), RegionGenerator::destruct(), RawCameraGenerator::destruct(), JPEGGenerator::destruct(), CDTGenerator::destruct(), setNumImages(), and ~FilterBankGenerator(). |
| void FilterBankGenerator::freeCaches |
( |
|
) |
[virtual] |
|
| unsigned int FilterBankGenerator::getBinSize |
( |
|
) |
const [virtual] |
|
|
|
calculates space needed to save - if you can't precisely add up the size, overestimate and things will still work.
- Returns:
- number of bytes read/written, 0 if error (or empty)
Implements LoadSave.
Reimplemented in CDTGenerator, InterleavedYUVGenerator, JPEGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, and SegmentedColorGenerator.
Definition at line 34 of file FilterBankGenerator.cc.
Referenced by SegmentedColorGenerator::getBinSize(), RLEGenerator::getBinSize(), RegionGenerator::getBinSize(), RawCameraGenerator::getBinSize(), JPEGGenerator::getBinSize(), InterleavedYUVGenerator::getBinSize(), CDTGenerator::getBinSize(), and RawCameraGenerator::SaveFileStream(). |
| unsigned int FilterBankGenerator::getFrameNumber |
( |
|
) |
const [inline] |
|
| unsigned int FilterBankGenerator::getFramesProcessed |
( |
|
) |
const [inline] |
|
| unsigned int FilterBankGenerator::getHeight |
( |
unsigned int |
layer |
) |
const [inline] |
|
|
|
returns height (in samples) of the image in a given layer
Definition at line 155 of file FilterBankGenerator.h.
Referenced by RLEGenerator::calcExpMaxRuns(), SegmentedColorGenerator::calcImage(), RLEGenerator::calcImage(), RawCameraGenerator::calcImage(), InterleavedYUVGenerator::calcImage(), FilterBankEvent::getHeight(), SegCamBehavior::openPacket(), RawCamBehavior::openPacket(), RawCameraGenerator::processEvent(), CDTGenerator::processEvent(), SegmentedColorGenerator::setDimensions(), RLEGenerator::setDimensions(), RegionGenerator::setDimensions(), JPEGGenerator::setDimensions(), and InterleavedYUVGenerator::setDimensions(). |
| unsigned char * FilterBankGenerator::getImage |
( |
unsigned int |
layer, |
|
|
unsigned int |
channel |
|
) |
const [virtual] |
|
|
|
returns pointer to the beginning of the image data for the specified layer and channel
this will cause the data to be calculated and cached if it's not already available
Definition at line 5 of file FilterBankGenerator.cc.
Referenced by SegmentedColorGenerator::calcImage(), RLEGenerator::calcImage(), RegionGenerator::calcImage(), JPEGGenerator::calcImage(), InterleavedYUVGenerator::calcImage(), FilterBankEvent::getImage(), RLEGenerator::getNumRuns(), RLEGenerator::getRun(), RLEGenerator::getRuns(), JPEGGenerator::LoadBuffer(), CameraBehavior::processEvent(), RawCameraGenerator::reconstructImage(), SegmentedColorGenerator::SaveBuffer(), RLEGenerator::SaveBuffer(), RegionGenerator::SaveBuffer(), RawCameraGenerator::SaveBuffer(), JPEGGenerator::SaveBuffer(), InterleavedYUVGenerator::SaveBuffer(), CDTGenerator::SaveBuffer(), RawCameraGenerator::SaveFileStream(), and RawCameraGenerator::upsampleImage(). |
| unsigned int FilterBankGenerator::getIncrement |
( |
unsigned int |
layer |
) |
const [inline] |
|
| virtual unsigned int FilterBankGenerator::getNumChannels |
( |
|
) |
const [inline, virtual] |
|
| virtual unsigned int FilterBankGenerator::getNumLayers |
( |
|
) |
const [inline, virtual] |
|
| virtual unsigned int FilterBankGenerator::getSelectedSaveChannel |
( |
|
) |
const [inline, virtual] |
|
| virtual unsigned int FilterBankGenerator::getSelectedSaveLayer |
( |
|
) |
const [inline, virtual] |
|
| unsigned int FilterBankGenerator::getSkip |
( |
unsigned int |
layer |
) |
const [inline] |
|
| unsigned int FilterBankGenerator::getStride |
( |
unsigned int |
layer |
) |
const [inline] |
|
| unsigned int FilterBankGenerator::getWidth |
( |
unsigned int |
layer |
) |
const [inline] |
|
|
|
returns width (in samples) of the image in a given layer
Definition at line 152 of file FilterBankGenerator.h.
Referenced by RLEGenerator::calcExpMaxRuns(), SegmentedColorGenerator::calcImage(), RLEGenerator::calcImage(), InterleavedYUVGenerator::calcImage(), FilterBankEvent::getWidth(), RLEGenerator::LoadBuffer(), SegCamBehavior::openPacket(), RawCamBehavior::openPacket(), SegmentedColorGenerator::processEvent(), RLEGenerator::processEvent(), RegionGenerator::processEvent(), RawCameraGenerator::processEvent(), JPEGGenerator::processEvent(), InterleavedYUVGenerator::processEvent(), CDTGenerator::processEvent(), RawCameraGenerator::reconstructImage(), SegmentedColorGenerator::setDimensions(), RLEGenerator::setDimensions(), RegionGenerator::setDimensions(), JPEGGenerator::setDimensions(), and InterleavedYUVGenerator::setDimensions(). |
| void FilterBankGenerator::invalidateCaches |
( |
|
) |
[virtual] |
|
| unsigned int FilterBankGenerator::LoadBuffer |
( |
const char |
buf[], |
|
|
unsigned int |
len |
|
) |
[virtual] |
|
|
|
The LoadBuffer() functions of the included subclasses aren't tested, so don't assume they'll work without a little debugging...
Implements LoadSave.
Reimplemented in CDTGenerator, InterleavedYUVGenerator, JPEGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, and SegmentedColorGenerator.
Definition at line 45 of file FilterBankGenerator.cc.
Referenced by SegmentedColorGenerator::LoadBuffer(), RLEGenerator::LoadBuffer(), RegionGenerator::LoadBuffer(), RawCameraGenerator::LoadBuffer(), JPEGGenerator::LoadBuffer(), and InterleavedYUVGenerator::LoadBuffer(). |
| virtual void FilterBankGenerator::processEvent |
( |
const EventBase & |
|
) |
[inline, virtual] |
|
| unsigned int FilterBankGenerator::SaveBuffer |
( |
char |
buf[], |
|
|
unsigned int |
len |
|
) |
const [virtual] |
|
|
|
Save to a given buffer.
- Parameters:
-
| buf | pointer to the memory where you should begin writing |
| len | length of buf available. (this isn't all yours, constrain yourself to what you returned in getBinSize() ) |
- Returns:
- the number of bytes actually used
Implements LoadSave.
Reimplemented in CDTGenerator, InterleavedYUVGenerator, JPEGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, and SegmentedColorGenerator.
Definition at line 61 of file FilterBankGenerator.cc.
Referenced by SegmentedColorGenerator::SaveBuffer(), RLEGenerator::SaveBuffer(), RegionGenerator::SaveBuffer(), RawCameraGenerator::SaveBuffer(), JPEGGenerator::SaveBuffer(), InterleavedYUVGenerator::SaveBuffer(), CDTGenerator::SaveBuffer(), RawCameraGenerator::SaveFileStream(), RawCamBehavior::writeColor(), SegCamBehavior::writeSeg(), and RawCamBehavior::writeSingleChannel(). |
| virtual void FilterBankGenerator::selectSaveImage |
( |
unsigned int |
layer, |
|
|
unsigned int |
channel |
|
) |
[inline, virtual] |
|
| void FilterBankGenerator::setNumImages |
( |
unsigned int |
nLayers, |
|
|
unsigned int |
nChannels |
|
) |
[protected, virtual] |
|
|
|
resizes the filter bank information storage area, you should override this to do your setup and call it from your constructor
In general, it isn't expected that FilterBankGenerator's should necessarily be dynamically resizeable (although it would be nice), which is why this isn't public. If yours is, just add some pubic accessor functions which call this. In general, the included subclasses should be able to handle being resized, but there's no reason to do so since the system won't be changing its available resolutions at run time.
Reimplemented in CDTGenerator, InterleavedYUVGenerator, JPEGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, and SegmentedColorGenerator.
Definition at line 78 of file FilterBankGenerator.cc.
Referenced by FilterBankGenerator(), SegmentedColorGenerator::setNumImages(), RLEGenerator::setNumImages(), RegionGenerator::setNumImages(), RawCameraGenerator::setNumImages(), JPEGGenerator::setNumImages(), InterleavedYUVGenerator::setNumImages(), and CDTGenerator::setNumImages(). |
Member Data Documentation
|
|
the current frame number - subclasses will need to set to the source's frameNumber when they receive a new frame (probably from processEvent())
The idea is to use this as a unique serial number for each frame. That way you can know if the current image in different generators is actually the same camera image before you try to compare or combine them.
You could also figure out the number of dropped frames by subtracting framesProcessed from this value. Give some leeway however, because it takes the first 40-70 frames just to boot up, so there's no way they can be processed.
Definition at line 254 of file FilterBankGenerator.h.
Referenced by FilterBankGenerator(), and getFrameNumber(). |
The documentation for this class was generated from the following files:
|