Homepage Demos Overview Downloads Tutorials 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

Definition at line 40 of file SegmentedColorGenerator.h.

Public Types

typedef 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 (EventBase::EventGeneratorID_t gid, unsigned int sid, unsigned int mysid)
 constructor

 SegmentedColorGenerator (EventBase::EventGeneratorID_t gid, unsigned int sid, unsigned int mysid, 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)

unsigned int getColorIndex (const std::string &name) const
 returns index of color corresponding to a string (uses a fast hash lookup)

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 unsigned int encodeColors (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 unsigned int decodeColors (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

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 ()
 sets width, height, skip, and stride parameters

virtual unsigned char * createImageCache (unsigned int layer, unsigned int chan) const
 create new image data storage area for the cache - this is only called when the corresponding entry in images is NULL

virtual void calcImage (unsigned int layer, unsigned int chan) const
 should calculate new image data, only called when imageValids indicates the image being requested is dirty


Protected Attributes

const FilterBankGeneratorsrc
 the generator of the last FilterBankEvent received

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

const unsigned int BITS_Y = 4
 bits of discretization for Y channel in the threshold map

const unsigned int BITS_U = 6
 bits of discretization for U channel in the threshold map

const unsigned int BITS_V = 6
 bits of discretization for V channel in the threshold map

const unsigned int NUM_Y = 1 << BITS_Y
 levels of discretization for Y channel in the threshold map

const unsigned int NUM_U = 1 << BITS_U
 levels of discretization for U channel in the threshold map

const unsigned int NUM_V = 1 << BITS_V
 levels of discretization for V channel in the threshold map

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


Member Typedef Documentation

typedef uchar SegmentedColorGenerator::cmap_t
 

type to use for color indexes

Definition at line 42 of file SegmentedColorGenerator.h.

Referenced by calcImage(), and loadThresholdMap().

typedef CMVision::color_class_state SegmentedColorGenerator::color_class_state
 

use CMVision's color structure

Definition at line 43 of file SegmentedColorGenerator.h.

Referenced by getColors().

typedef __gnu_cxx::hash_map<const char*, unsigned int, __gnu_cxx::hash<const char*>, hashcmp_eqstr> SegmentedColorGenerator::hashmap
 

a shorthand for the hash structure that CMVision expects for the color lookups

Definition at line 44 of file SegmentedColorGenerator.h.


Constructor & Destructor Documentation

SegmentedColorGenerator::SegmentedColorGenerator EventBase::EventGeneratorID_t  gid,
unsigned int  sid,
unsigned int  mysid
 

constructor

Definition at line 9 of file SegmentedColorGenerator.cc.

SegmentedColorGenerator::SegmentedColorGenerator EventBase::EventGeneratorID_t  gid,
unsigned int  sid,
unsigned int  mysid,
unsigned int  syc,
unsigned int  suc,
unsigned int  svc
 

constructor, you can pass which channels to use as Y, U, & V channels

Definition at line 15 of file SegmentedColorGenerator.cc.

SegmentedColorGenerator::~SegmentedColorGenerator  )  [virtual]
 

destructor

Definition at line 21 of file SegmentedColorGenerator.cc.

SegmentedColorGenerator::SegmentedColorGenerator const SegmentedColorGenerator fbk  )  [private]
 

don't call


Member Function Documentation

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

should calculate new image data, only called when imageValids indicates the image being requested is dirty

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

Implements FilterBankGenerator.

Definition at line 209 of file SegmentedColorGenerator.cc.

unsigned char * SegmentedColorGenerator::createImageCache unsigned int  layer,
unsigned int  chan
const [protected, virtual]
 

create new image data storage area for the cache - this is only called when the corresponding entry in images is NULL

You should return the pointer you want stored in images to be returned by any calls to getFirstRow. Interpretation of the data it points to is dependant on the the generator which creates it

Implements FilterBankGenerator.

Definition at line 204 of file SegmentedColorGenerator.cc.

Referenced by LoadBuffer().

unsigned int SegmentedColorGenerator::decodeColors const char  buf[],
unsigned int  len
[virtual]
 

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)

Definition at line 172 of file SegmentedColorGenerator.cc.

Referenced by LoadBuffer().

unsigned int SegmentedColorGenerator::encodeColors char  buf[],
unsigned int  len
const [virtual]
 

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)

Definition at line 155 of file SegmentedColorGenerator.cc.

Referenced by SaveBuffer(), and SegCamBehavior::writeRLE().

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

Reimplemented from FilterBankGenerator.

Definition at line 87 of file SegmentedColorGenerator.cc.

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

Reimplemented from BehaviorBase.

Definition at line 53 of file SegmentedColorGenerator.h.

unsigned int SegmentedColorGenerator::getColorIndex const std::string &  name  )  const [inline]
 

returns index of color corresponding to a string (uses a fast hash lookup)

Definition at line 81 of file SegmentedColorGenerator.h.

unsigned int SegmentedColorGenerator::getColorIndex const char *  name  )  const [inline]
 

returns index of color corresponding to a string (uses a fast hash lookup)

Definition at line 74 of file SegmentedColorGenerator.h.

Referenced by getColorIndex().

virtual color_class_state* SegmentedColorGenerator::getColors  )  [inline, virtual]
 

gives direct access to the color information

Definition at line 71 of file SegmentedColorGenerator.h.

virtual const color_class_state* SegmentedColorGenerator::getColors  )  const [inline, virtual]
 

gives direct access to the color information

Definition at line 68 of file SegmentedColorGenerator.h.

Referenced by processEvent().

virtual unsigned int SegmentedColorGenerator::getNumColors  )  const [inline, virtual]
 

returns the number of different colors available

Definition at line 65 of file SegmentedColorGenerator.h.

Referenced by processEvent().

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 95 of file SegmentedColorGenerator.cc.

bool SegmentedColorGenerator::loadColorInfo const std::string &  col_file  )  [virtual]
 

loads color information from a file, returns false if failed, true otherwise

Definition at line 65 of file SegmentedColorGenerator.cc.

Referenced by StartupBehavior::initVision().

unsigned int SegmentedColorGenerator::loadThresholdMap const std::string &  tm_file  )  [virtual]
 

loads a threshold map into memory from a file, returns -1U if failed, otherwise returns corresponding channel

Definition at line 43 of file SegmentedColorGenerator.cc.

const SegmentedColorGenerator& SegmentedColorGenerator::operator= const SegmentedColorGenerator fbk  )  [private]
 

don't call

void SegmentedColorGenerator::processEvent const EventBase event  )  [virtual]
 

should receive FilterBankEvents from any standard format FilterBankGenerator (like RawCameraGenerator)

Reimplemented from FilterBankGenerator.

Definition at line 28 of file SegmentedColorGenerator.cc.

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

Reimplemented from FilterBankGenerator.

Definition at line 129 of file SegmentedColorGenerator.cc.

void SegmentedColorGenerator::setDimensions  )  [protected, virtual]
 

sets width, height, skip, and stride parameters

Definition at line 189 of file SegmentedColorGenerator.cc.

Referenced by processEvent().

void SegmentedColorGenerator::setNumImages unsigned int  nLayers,
unsigned int  nChannels
[protected, virtual]
 

ignores nChannels - the number of channels is always the number of loaded threshold maps

Reimplemented from FilterBankGenerator.

Definition at line 199 of file SegmentedColorGenerator.cc.

Referenced by loadThresholdMap(), processEvent(), and SegmentedColorGenerator().


Member Data Documentation

const unsigned int SegmentedColorGenerator::BITS_U = 6 [static, protected]
 

bits of discretization for U channel in the threshold map

Definition at line 92 of file SegmentedColorGenerator.h.

Referenced by calcImage(), and loadThresholdMap().

const unsigned int SegmentedColorGenerator::BITS_V = 6 [static, protected]
 

bits of discretization for V channel in the threshold map

Definition at line 93 of file SegmentedColorGenerator.h.

Referenced by calcImage(), and loadThresholdMap().

const unsigned int SegmentedColorGenerator::BITS_Y = 4 [static, protected]
 

bits of discretization for Y channel in the threshold map

Definition at line 91 of file SegmentedColorGenerator.h.

Referenced by calcImage(), and loadThresholdMap().

hashmap SegmentedColorGenerator::colorNames [protected]
 

look up color indexes corresponding to names

Definition at line 116 of file SegmentedColorGenerator.h.

Referenced by getColorIndex(), loadColorInfo(), and processEvent().

color_class_state SegmentedColorGenerator::colors[MAX_COLORS] [protected]
 

array of available colors

Definition at line 115 of file SegmentedColorGenerator.h.

Referenced by decodeColors(), encodeColors(), getColors(), and loadColorInfo().

const unsigned int SegmentedColorGenerator::MAX_COLORS = 20 [static, protected]
 

maximum number of different colors that can be segmented

Definition at line 97 of file SegmentedColorGenerator.h.

Referenced by loadColorInfo().

const unsigned int SegmentedColorGenerator::NUM_U = 1 << BITS_U [static, protected]
 

levels of discretization for U channel in the threshold map

Definition at line 95 of file SegmentedColorGenerator.h.

Referenced by loadColorInfo(), and loadThresholdMap().

const unsigned int SegmentedColorGenerator::NUM_V = 1 << BITS_V [static, protected]
 

levels of discretization for V channel in the threshold map

Definition at line 96 of file SegmentedColorGenerator.h.

Referenced by loadColorInfo(), and loadThresholdMap().

const unsigned int SegmentedColorGenerator::NUM_Y = 1 << BITS_Y [static, protected]
 

levels of discretization for Y channel in the threshold map

Definition at line 94 of file SegmentedColorGenerator.h.

Referenced by loadColorInfo(), and loadThresholdMap().

unsigned int SegmentedColorGenerator::numColors [protected]
 

number of available colors

Definition at line 114 of file SegmentedColorGenerator.h.

Referenced by decodeColors(), encodeColors(), getNumColors(), loadColorInfo(), and loadThresholdMap().

const FilterBankGenerator* SegmentedColorGenerator::src [protected]
 

the generator of the last FilterBankEvent received

Definition at line 105 of file SegmentedColorGenerator.h.

Referenced by calcImage(), processEvent(), and setDimensions().

unsigned int SegmentedColorGenerator::srcUChan [protected]
 

the channel of the source's U channel

Definition at line 107 of file SegmentedColorGenerator.h.

Referenced by calcImage().

unsigned int SegmentedColorGenerator::srcVChan [protected]
 

the channel of the source's V channel

Definition at line 108 of file SegmentedColorGenerator.h.

Referenced by calcImage().

unsigned int SegmentedColorGenerator::srcYChan [protected]
 

the channel of the source's Y channel

Definition at line 106 of file SegmentedColorGenerator.h.

Referenced by calcImage().

std::vector<std::string> SegmentedColorGenerator::tmapNames [protected]
 

filename of each tmap;

Definition at line 112 of file SegmentedColorGenerator.h.

Referenced by loadColorInfo(), and loadThresholdMap().

std::vector<cmap_t*> SegmentedColorGenerator::tmaps [protected]
 

list of threshold maps so you can segment the same source different ways

Definition at line 111 of file SegmentedColorGenerator.h.

Referenced by calcImage(), loadColorInfo(), loadThresholdMap(), setNumImages(), and ~SegmentedColorGenerator().


The documentation for this class was generated from the following files:
Tekkotsu v2.0
Generated Wed Jan 21 03:23:25 2004 by Doxygen 1.3.4