Image Component Library (ICL)
Public Member Functions | Private Member Functions | Private Attributes | List of all members
icl::cv::HoughLineDetector Class Reference

#include <HoughLineDetector.h>

Inheritance diagram for icl::cv::HoughLineDetector:
icl::utils::Configurable

Public Member Functions

 HoughLineDetector (float dRho=0.1, float dR=10, const utils::Range32f &rRange=utils::Range32f(0,::sqrt(640 *640+480 *480)), float rInhibitionRange=10, float rhoInhibitionRange=0.3, bool gaussianInhibition=true, bool blurHoughSpace=true, bool dilateEntries=true, bool blurredSampling=false)
 Create a new HoughLineDetectorInstance. More...
 
 ~HoughLineDetector ()
 
void add (const utils::Point &p)
 adds a new point More...
 
void add (const std::vector< utils::Point > &ps)
 adds new points More...
 
void add (const utils::Point32f &p)
 adds a new point More...
 
void add (const std::vector< utils::Point32f > &ps)
 adds new points More...
 
template<class T >
void add (const math::FixedColVector< T, 2 > &p)
 adds a new point More...
 
template<class T >
void add (const std::vector< const math::FixedColVector< T, 2 > > &ps)
 adds new points More...
 
void add (const core::Img8u &binaryImage)
 adds all non zero pixels of the given binary image More...
 
const core::Img32sgetImage () const
 returns current hough-table image More...
 
const core::Img32fgetInhibitionMap () const
 returns current gaussian inhibition map More...
 
void reset ()
 sets all hough table entries to 0 More...
 
std::vector< math::StraightLine2DgetLines (int max, bool resetAfterwards=true)
 detects up to max lines More...
 
std::vector< math::StraightLine2DgetLines (int max, std::vector< float > &significances, bool resetAfterwards=true)
 detects up to max lines and pushes the line significances into given destination vector More...
 
- Public Member Functions inherited from icl::utils::Configurable
virtual ~Configurable ()
 virtual destructor More...
 
 Configurable (const Configurable &other)
 Copy constructor. More...
 
Configurableoperator= (const Configurable &other)
 Assignment operator. More...
 
void setConfigurableID (const std::string &ID)
 sets the ID of this configurable More...
 
const std::string & getConfigurableID () const
 returns the configurables static ID More...
 
bool isOrderedFlagSet () const
 returns whether the ordered flag is set More...
 
void deactivateProperty (const std::string &pattern)
 adds an additional deativation pattern More...
 
void deleteDeactivationPattern (const std::string &pattern)
 removed a formerly added deactivation pattern More...
 
std::vector< std::string > getPropertyListWithoutDeactivated () const
 this returns a filtered list of properties (using all filters added by deactivateProperty) More...
 
virtual void adaptProperty (const std::string &name, const std::string &newType, const std::string &newInfo, const std::string &newToolTip)
 this function can be used to adapt a specific property afterwards More...
 
void registerCallback (const Callback &cb)
 add a callback for changed properties More...
 
void removedCallback (const Callback &cb)
 removes a callback that was registered before More...
 
void syncChangesTo (Configurable *others, int num=1)
 this can be used to let this instance also apply property changes to others More...
 
virtual void setPropertyValue (const std::string &propertyName, const Any &value)
 sets a property value More...
 
virtual std::vector< std::string > getPropertyList () const
 returns a list of All properties, that can be set using setProperty More...
 
virtual bool supportsProperty (const std::string &propertyName) const
 base implementation for property check (seaches in the property list) More...
 
virtual void saveProperties (const std::string &filename, const std::vector< std::string > &propertiesToSkip=EMPTY_VEC) const
 writes all available properties into a file More...
 
virtual void loadProperties (const std::string &filename, const std::vector< std::string > &propertiesToSkip=EMPTY_VEC)
 reads a camera config file from disc More...
 
virtual std::string getPropertyType (const std::string &propertyName) const
 get type of property More...
 
virtual std::string getPropertyInfo (const std::string &propertyName) const
 get information of a properties valid values More...
 
virtual Any getPropertyValue (const std::string &propertyName) const
 returns the current value of a property or a parameter More...
 
virtual std::string getPropertyToolTip (const std::string &propertyName) const
 returns the tooltip description for a given property More...
 
virtual int getPropertyVolatileness (const std::string &propertyName) const
 Returns whether this property may be changed internally. More...
 

Private Member Functions

void prepare_all ()
 
void prepare (float dRho, float dR, const utils::Range32f &rRange, float rInhibitionRange, float rhoInhibitionRange, bool gaussianInhibition=true, bool blurHoughSpace=true, bool dilateEntries=true, bool blurredSampling=false)
 initializes the HoughLineDetector More...
 
float r (float rho, float x, float y) const
 internal utility function More...
 
int getX (float rho) const
 internal utility function More...
 
int getY (float r) const
 internal utility function More...
 
float getRho (int x) const
 internal utility function More...
 
float getR (int y) const
 internal utility function More...
 
void incLut (float rho, float r)
 internal utility function More...
 
void incLutBlurred (float rho, float r)
 internal utility function More...
 
int & cyclicLUT (int x, int y)
 internal utility function More...
 
void apply_inhibition (const utils::Point &p)
 internal utility function More...
 
void add_intern (float x, float y)
 internal utility function More...
 
void add_intern2 (float x, float y)
 internal utility function More...
 
void blur_hough_space_if_necessary ()
 internal utility function More...
 

Private Attributes

Data * m_data
 

Additional Inherited Members

- Public Types inherited from icl::utils::Configurable
typedef Function< void, const Property & > Callback
 Function type for changed properties. More...
 
- Static Public Member Functions inherited from icl::utils::Configurable
static std::string create_default_ID (const std::string &prefix)
 this function can be used in subclasses to create a default ID More...
 
static Configurableget (const std::string &id)
 returns configurable by given ID More...
 
static void register_configurable_type (const std::string &classname, Function< Configurable * > creator)
 registers a configurable type More...
 
static std::vector< std::string > get_registered_configurables ()
 returns a list of all registered configurable classnames More...
 
static Configurablecreate_configurable (const std::string &classname)
 creates a configurable by given name More...
 
- Static Public Attributes inherited from icl::utils::Configurable
static const std::vector< std::string > EMPTY_VEC
 used as shortcut – just an empty vector of std::strings More...
 
- Protected Member Functions inherited from icl::utils::Configurable
void addProperty (const std::string &name, const std::string &type, const std::string &info, const Any &value=Any(), const int volatileness=0, const std::string &tooltip=std::string())
 This can be used by derived classes to store supported properties in the internal list. More...
 
void addChildConfigurable (Configurable *configurable, const std::string &childPrefix="")
 This adds another configurable as child. More...
 
void removeChildConfigurable (Configurable *configurable)
 removes the given child configurable More...
 
Propertyprop (const std::string &propertyName)
 this CAN be used e.g. to store a property value in internal property-list More...
 
const Propertyprop (const std::string &propertyName) const
 this CAN be used e.g. to store a property value in internal property-list More...
 
 Configurable (const std::string &ID="", bool ordered=true)
 create this configurable with given ID More...
 
void call_callbacks (const std::string &propertyName, const Configurable *caller) const
 calls all registered callbacks More...
 
- Protected Attributes inherited from icl::utils::Configurable
std::vector< Callbackcallbacks
 internally managed list of callbacks More...
 

Detailed Description

LineDetection class using hough-space line detection

Algorithms

Image lines (of infinite length) can be described by a tuple (rho,r) and the line equation $r = x\cdot cos(rho) + y\cdot sin(rho)$. Each pixel (x,y) belongs potentially to a all lines (rho,r) where this equation is true. Internally, the space of possible lines (sometimes referred a the hough-space) is sampled (internally we use an instance of core::Img32s). Rho is mapped to the x-axis (x=0 -> rho=0, x=width-1 -> rho = 2*M_PI) and r is mapped to the y-axis (y=0 -> r=minR, y=height-1 -> r=maxR). So the size of the internal hough-space becomes 2*M_PI/dRho x (rRange.max-rRange.min)/dR.

When a new border pixel (x,y) is added, the probability of each potential line that intersects (x,y) is increased. Technically this is performed by computing r(rho) for all possible values rho (all samples) with the formula for r above which leads to values (rho,r) which's hough-space entries are increased by one. The best line matches can be computed from the maxima in the resulting hough space.

Optimizations

To enhance line detection performance, the HoughLineDetector provides a set of optimization approaches:

Local inhibition around detected lines

As a single image line, might result in 2 or even more lines in the hough-space (because of spacial noise in the pixels detection procedure), the hough-space is locally inhibited around already detected lines. The amount of this inhibition procedure can be set by the constructor parameters (rInhibitionRange and rhoInhibitionRange).

Gaussian inhibition

Sometimes hard borders of the inhibition sub-window lead to random 2nd and 3rd detected line values. To stabilize this, inhibition can be set up to be 'gaussian-blurred', which means, that hough-table entries that are very close to already detected lines are nearly removed completely and those that are also in the inhibition sub-rect but some pixels away from the detected line center are inhibited less.

Gaussian inhibition

Resulting from the sampling procedure of both, that actual image space and the hough-space, entries in the hough-space might have hard borders or even gaps. To avoid this, three different optimization techniques are provided, which can all be combined.

Blurring the hough space

This means, that the hough-space is simply blurred using a 3x3 linear gaussian filter. This optimization provides much more stable results, but it also entails a higher computational expense.

Dilation of pixel entries

If this optimization is activated, no only the given pixel (x,y) is added internally, but also it's 4 direct neighbour pixels. This also leads to a kind of blurred hough table

Blurred sampling of lines

This optimization changes the line-sampling procedure. When a line is sampled for all rho-values using r = x cos(rho) + y sin(rho), not only the resulting pixel p in the hough table is increased, but also the pixel above, and the pixel below (actually, the exactly computed pixel p is increased by 2 and it's upper and lower neighbour's are increased by one). This again leads to a blurring effect. however, the other two optimzations provides better results. It's worth mention, that this optimization's additional computational expense is low in comparison to the other two optizations.

Constructor & Destructor Documentation

◆ HoughLineDetector()

icl::cv::HoughLineDetector::HoughLineDetector ( float  dRho = 0.1,
float  dR = 10,
const utils::Range32f &  rRange = utils::Range32f(0,::sqrt(640 *640+480 *480)),
float  rInhibitionRange = 10,
float  rhoInhibitionRange = 0.3,
bool  gaussianInhibition = true,
bool  blurHoughSpace = true,
bool  dilateEntries = true,
bool  blurredSampling = false 
)

Create a new HoughLineDetectorInstance.

Parameters
dRholine angle sampling distance
dRline distance to 0 sampling factor
rRangerange of line distances
rInhibitionRangevertical radius for local inhibition
rhoInhibitionRangehorizontal radius for local inhibition
gaussianInhibitionenables gaussian inhibition
blurHoughSpaceenables hough space blurring
dilateEntriesenables entry dilatation
blurredSamplingenables blurred sampling

◆ ~HoughLineDetector()

icl::cv::HoughLineDetector::~HoughLineDetector ( )

Member Function Documentation

◆ add() [1/7]

void icl::cv::HoughLineDetector::add ( const utils::Point p)

adds a new point

◆ add() [2/7]

void icl::cv::HoughLineDetector::add ( const std::vector< utils::Point > &  ps)

adds new points

◆ add() [3/7]

void icl::cv::HoughLineDetector::add ( const utils::Point32f p)

adds a new point

◆ add() [4/7]

void icl::cv::HoughLineDetector::add ( const std::vector< utils::Point32f > &  ps)

adds new points

◆ add() [5/7]

template<class T >
void icl::cv::HoughLineDetector::add ( const math::FixedColVector< T, 2 > &  p)
inline

adds a new point

◆ add() [6/7]

template<class T >
void icl::cv::HoughLineDetector::add ( const std::vector< const math::FixedColVector< T, 2 > > &  ps)
inline

adds new points

◆ add() [7/7]

void icl::cv::HoughLineDetector::add ( const core::Img8u binaryImage)

adds all non zero pixels of the given binary image

◆ add_intern()

void icl::cv::HoughLineDetector::add_intern ( float  x,
float  y 
)
private

internal utility function

◆ add_intern2()

void icl::cv::HoughLineDetector::add_intern2 ( float  x,
float  y 
)
private

internal utility function

◆ apply_inhibition()

void icl::cv::HoughLineDetector::apply_inhibition ( const utils::Point p)
private

internal utility function

◆ blur_hough_space_if_necessary()

void icl::cv::HoughLineDetector::blur_hough_space_if_necessary ( )
private

internal utility function

◆ cyclicLUT()

int& icl::cv::HoughLineDetector::cyclicLUT ( int  x,
int  y 
)
private

internal utility function

◆ getImage()

const core::Img32s& icl::cv::HoughLineDetector::getImage ( ) const

returns current hough-table image

◆ getInhibitionMap()

const core::Img32f& icl::cv::HoughLineDetector::getInhibitionMap ( ) const

returns current gaussian inhibition map

◆ getLines() [1/2]

std::vector<math::StraightLine2D> icl::cv::HoughLineDetector::getLines ( int  max,
bool  resetAfterwards = true 
)

detects up to max lines

◆ getLines() [2/2]

std::vector<math::StraightLine2D> icl::cv::HoughLineDetector::getLines ( int  max,
std::vector< float > &  significances,
bool  resetAfterwards = true 
)

detects up to max lines and pushes the line significances into given destination vector

significances are relative to the first line match, which's significance is always 1.0

◆ getR()

float icl::cv::HoughLineDetector::getR ( int  y) const
private

internal utility function

◆ getRho()

float icl::cv::HoughLineDetector::getRho ( int  x) const
private

internal utility function

◆ getX()

int icl::cv::HoughLineDetector::getX ( float  rho) const
private

internal utility function

◆ getY()

int icl::cv::HoughLineDetector::getY ( float  r) const
private

internal utility function

◆ incLut()

void icl::cv::HoughLineDetector::incLut ( float  rho,
float  r 
)
private

internal utility function

◆ incLutBlurred()

void icl::cv::HoughLineDetector::incLutBlurred ( float  rho,
float  r 
)
private

internal utility function

◆ prepare()

void icl::cv::HoughLineDetector::prepare ( float  dRho,
float  dR,
const utils::Range32f &  rRange,
float  rInhibitionRange,
float  rhoInhibitionRange,
bool  gaussianInhibition = true,
bool  blurHoughSpace = true,
bool  dilateEntries = true,
bool  blurredSampling = false 
)
private

initializes the HoughLineDetector

◆ prepare_all()

void icl::cv::HoughLineDetector::prepare_all ( )
private

◆ r()

float icl::cv::HoughLineDetector::r ( float  rho,
float  x,
float  y 
) const
private

internal utility function

◆ reset()

void icl::cv::HoughLineDetector::reset ( )

sets all hough table entries to 0

Member Data Documentation

◆ m_data

Data* icl::cv::HoughLineDetector::m_data
private

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