Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SegmentedColorGenerator Class Reference

#include <SegmentedColorGenerator.h>

Inheritance diagram for SegmentedColorGenerator:

Inheritance graph
[legend]
List of all members.

Detailed Description

Generates FilterBankEvents indexed color images based on a color threshold file.

Pretty simple idea - use a big mapping of YUV values to lookup index values.

Threshold files are 16x64x64 = 64KB. So each Y component is discretized into 16 levels, U and V into 64 each. Then the appropriate element of the 3D matrix is looked up, which holds the desired index for that color. The threshold files are generated offline. See http://www.tekkotsu.org/CameraSetup.html

The color information is shared for all threshold files in this object.

The row skip is always 0, and the row stride is always width. But it would be better to use the proper accessor functions to be more general.

Should receive FilterBankEvents from any standard format FilterBankGenerator (like RawCameraGenerator) However, images that use an increment!=1 will break.

The events which are produced are SegmentedColorFilterBankEvents, which will allow you to reference the color information later on. Keep in mind that the region and area statistic fields are not filled out at this stage... the RegionGenerator will complete the processing if you want that info as well.

Uses the CMVision library for main processing

The format used for serialization is: (code is in saveBuffer())

  • <FilterBankGenerator: superclass header> (First saves the superclass's info)
  • <string: "SegColorImage"> (remember a 'string' is len+str+0; so this is the literal "\015\0\0\0SegColorImage\0"; also remember "\015" is octal for 13)
  • <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

For more information on serialization, see FilterBankGenerator

Definition at line 53 of file SegmentedColorGenerator.h.

Public Types

typedef CMVision::uchar cmap_t
 type to use for color indexes
typedef CMVision::color_class_state color_class_state
 use CMVision's color structure
typedef __gnu_cxx::hash_map<
const char *, unsigned int,
__gnu_cxx::hash< const char * >,
hashcmp_eqstr
hashmap
 a shorthand for the hash structure that CMVision expects for the color lookups

Public Member Functions

 SegmentedColorGenerator (unsigned int mysid, FilterBankGenerator *fbg, EventBase::EventTypeID_t tid)
 constructor
 SegmentedColorGenerator (unsigned int mysid, FilterBankGenerator *fbg, EventBase::EventTypeID_t tid, unsigned int syc, unsigned int suc, unsigned int svc)
 constructor, you can pass which channels to use as Y, U, & V channels
virtual ~SegmentedColorGenerator ()
 destructor
virtual void processEvent (const EventBase &event)
 should receive FilterBankEvents from any standard format FilterBankGenerator (like RawCameraGenerator)
virtual unsigned int loadThresholdMap (const std::string &tm_file)
 loads a threshold map into memory from a file, returns -1U if failed, otherwise returns corresponding channel
virtual bool loadColorInfo (const std::string &col_file)
 loads color information from a file, returns false if failed, true otherwise
virtual unsigned int getNumColors () const
 returns the number of different colors available
virtual const color_class_stategetColors () const
 gives direct access to the color information
virtual color_class_stategetColors ()
 gives direct access to the color information
unsigned int getColorIndex (const char *name) const
 returns index of color corresponding to a string (uses a fast hash lookup), or -1U if not found
unsigned int getColorIndex (const std::string &name) const
 returns index of color corresponding to a string (uses a fast hash lookup), or -1U if not found
unsigned int getColorIndex (const rgb color) const
 returns index of color corresponding to a specific rgb color, or -1U if not found
rgb getColorRGB (const unsigned int index) const
 returns rgb struct (from colors.h) corresponding to an int index. Returns black if index is invalid.
rgb getColorRGB (const char *name) const
 returns rgb struct (from colors.h) corresponding to a string. Returns black if index is invalid.
rgb getColorRGB (const std::string &name) const
 returns rgb struct (from colors.h) corresponding to a string. Returns black if index is invalid.
const char * getColorName (const unsigned int index) const
 returns the name of a color given its index
virtual unsigned int getBinSize () const
 Calculates space needed to save - if you can't precisely add up the size, just make sure to 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 in memory.
virtual bool encodeColorsInc (char *&buf, unsigned int &len) const
 in case you want to only save the color info but not the image (this is binary - *not* the same format as what's read in loadColorInfo)
virtual bool decodeColorsInc (const char *&buf, unsigned int &len)
 in case you want to only load the color info but not the image (this is binary - *not* the same format as what's read in loadColorInfo)

Static Public Member Functions

static std::string getClassDescription ()
 Gives a short description of what this class of behaviors does... you should override this (but don't have to).

Protected Member Functions

virtual void setNumImages (unsigned int nLayers, unsigned int nChannels)
 ignores nChannels - the number of channels is always the number of loaded threshold maps
virtual void setDimensions ()
virtual unsigned char * createImageCache (unsigned int layer, unsigned int chan) const
 creates the image cache width[layer]*height[layer] + 1 -- why plus one? Because CMVision temporarily scribbles one-past end of each row
virtual void calcImage (unsigned int layer, unsigned int chan)
 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())

Protected Attributes

unsigned int srcYChan
 the channel of the source's Y channel
unsigned int srcUChan
 the channel of the source's U channel
unsigned int srcVChan
 the channel of the source's V channel
std::vector< cmap_t * > tmaps
 list of threshold maps so you can segment the same source different ways
std::vector< std::string > tmapNames
 filename of each tmap;
unsigned int numColors
 number of available colors
color_class_state colors [MAX_COLORS]
 array of available colors
hashmap colorNames
 look up color indexes corresponding to names

Static Protected Attributes

static const unsigned int BITS_Y = 4
 bits of discretization for Y channel in the threshold map
static const unsigned int BITS_U = 6
 bits of discretization for U channel in the threshold map
static const unsigned int BITS_V = 6
 bits of discretization for V channel in the threshold map
static const unsigned int NUM_Y = 1 << BITS_Y
 levels of discretization for Y channel in the threshold map
static const unsigned int NUM_U = 1 << BITS_U
 levels of discretization for U channel in the threshold map
static const unsigned int NUM_V = 1 << BITS_V
 levels of discretization for V channel in the threshold map
static const unsigned int MAX_COLORS = 20
 maximum number of different colors that can be segmented

Private Member Functions

 SegmentedColorGenerator (const SegmentedColorGenerator &fbk)
 don't call
const SegmentedColorGeneratoroperator= (const SegmentedColorGenerator &fbk)
 don't call

Classes

class  NoThresholdException
 thrown if no threshold maps are available More...


Member Function Documentation

void SegmentedColorGenerator::calcImage ( unsigned int  layer,
unsigned int  chan 
) [protected, virtual]

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())

This is where you'll want to put your user-specific code for calculating the image data

Implements FilterBankGenerator.

Definition at line 214 of file SegmentedColorGenerator.cc.

unsigned int SegmentedColorGenerator::getBinSize (  )  const [virtual]

Calculates space needed to save - if you can't precisely add up the size, just make sure to overestimate and things will still work.

getBinSize is used for reserving buffers during serialization, but does not necessarily determine the actual size of what is written -- the return value of saveBuffer() specifies that after the data actually has been written. If getBinSize overestimates, the extra memory allocation is only temporary, no extra filler bytes are actually stored.

Returns:
number of bytes read/written, 0 if error (or empty)

Reimplemented from FilterBankGenerator.

Definition at line 106 of file SegmentedColorGenerator.cc.

static std::string SegmentedColorGenerator::getClassDescription (  )  [inline, static]

Gives a short description of what this class of behaviors does... you should override this (but don't have to).

If you do override this, also consider overriding getDescription() to return it

Reimplemented from BehaviorBase.

Definition at line 66 of file SegmentedColorGenerator.h.

unsigned int SegmentedColorGenerator::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...

Reimplemented from FilterBankGenerator.

Definition at line 114 of file SegmentedColorGenerator.cc.

unsigned int SegmentedColorGenerator::saveBuffer ( char  buf[],
unsigned int  len 
) const [virtual]

Save to a given buffer in memory.

Parameters:
buf pointer to the memory where you should begin writing
len length of buf available. (this isn't necessarily all yours, constrain yourself to what you returned in getBinSize() )
Returns:
the number of bytes actually used

Reimplemented from FilterBankGenerator.

Definition at line 142 of file SegmentedColorGenerator.cc.

void SegmentedColorGenerator::setDimensions (  )  [protected, virtual]

sets stride parameter to width (as set by FilterBankGenerator::setDimensions())

Reimplemented from FilterBankGenerator.

Definition at line 194 of file SegmentedColorGenerator.cc.


The documentation for this class was generated from the following files:

Tekkotsu v3.0
Generated Fri May 11 20:08:45 2007 by Doxygen 1.4.7