Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpTemplateTrackerZone Class Reference

#include <visp3/tt/vpTemplateTrackerZone.h>

Public Member Functions

 vpTemplateTrackerZone ()
 
 vpTemplateTrackerZone (const vpTemplateTrackerZone &z)
 
virtual ~vpTemplateTrackerZone ()
 
void add (const vpTemplateTrackerTriangle &t)
 
void clear ()
 
void copy (const vpTemplateTrackerZone &z)
 
void display (const vpImage< unsigned char > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
 
void display (const vpImage< vpRGBa > &I, const vpColor &col=vpColor::green, unsigned int thickness=3)
 
void fillTriangle (vpImage< unsigned char > &I, unsigned int id, unsigned char gray_level)
 
double getArea () const
 
vpImagePoint getCenter () const
 
vpImagePoint getCenter (int borne_x, int borne_y) const
 
int getMaxx () const
 
int getMaxy () const
 
int getMinx () const
 
int getMiny () const
 
vpRect getBoundingBox () const
 
unsigned int getNbTriangle () const
 
vpTemplateTrackerZone getPyramidDown () const
 
void getTriangle (unsigned int i, vpTemplateTrackerTriangle &T) const
 
vpTemplateTrackerTriangle getTriangle (unsigned int i) const
 
void initClick (const vpImage< unsigned char > &I, bool delaunay=false)
 
void initFromPoints (const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &ip, bool delaunay=false)
 
bool inZone (const int &i, const int &j) const
 
bool inZone (const double &i, const double &j) const
 
bool inZone (const int &i, const int &j, unsigned int &id_triangle) const
 
bool inZone (const double &i, const double &j, unsigned int &id_triangle) const
 
vpTemplateTrackerZoneoperator= (const vpTemplateTrackerZone &z)
 

Protected Attributes

std::vector< vpTemplateTrackerTriangleZone
 
int min_x
 
int min_y
 
int max_x
 
int max_y
 

Detailed Description

A zone is defined by a set of triangles defined as vpTemplateTrackerTriangle.

A zone can be initialized either by user interaction using mouse click in a display device throw initClick(), or by a list of points throw initFromPoints().

Examples
templateTracker.cpp.

Definition at line 63 of file vpTemplateTrackerZone.h.

Constructor & Destructor Documentation

◆ vpTemplateTrackerZone() [1/2]

BEGIN_VISP_NAMESPACE vpTemplateTrackerZone::vpTemplateTrackerZone ( )

Default constructor.

Definition at line 48 of file vpTemplateTrackerZone.cpp.

◆ vpTemplateTrackerZone() [2/2]

vpTemplateTrackerZone::vpTemplateTrackerZone ( const vpTemplateTrackerZone z)

Copy constructor.

Definition at line 53 of file vpTemplateTrackerZone.cpp.

◆ ~vpTemplateTrackerZone()

vpTemplateTrackerZone::~vpTemplateTrackerZone ( )
virtual

Destructor.

Definition at line 478 of file vpTemplateTrackerZone.cpp.

References clear().

Member Function Documentation

◆ add()

void vpTemplateTrackerZone::add ( const vpTemplateTrackerTriangle t)

Add a triangle to the zone and update the bounding box.

Parameters
t: Triangle to introduce in the zone.

Definition at line 247 of file vpTemplateTrackerZone.cpp.

References vpTemplateTrackerTriangle::getMaxx(), vpTemplateTrackerTriangle::getMaxy(), vpTemplateTrackerTriangle::getMinx(), vpTemplateTrackerTriangle::getMiny(), max_x, max_y, min_x, min_y, and Zone.

Referenced by copy(), getPyramidDown(), initFromPoints(), and vpTemplateTrackerWarp::warpZone().

◆ clear()

void vpTemplateTrackerZone::clear ( )

Remove all the triangles that define the zone.

Definition at line 62 of file vpTemplateTrackerZone.cpp.

References max_x, max_y, min_x, min_y, and Zone.

Referenced by operator=(), vpTemplateTrackerWarp::warpZone(), and ~vpTemplateTrackerZone().

◆ copy()

void vpTemplateTrackerZone::copy ( const vpTemplateTrackerZone z)

Copy all the triangles that define zone Z in the current zone (*this) and update the zone bounding box.

Parameters
z: Zone with a set of triangles provided as input.

Definition at line 522 of file vpTemplateTrackerZone.cpp.

References add(), vpTemplateTrackerTriangle::getMaxx(), vpTemplateTrackerTriangle::getMaxy(), vpTemplateTrackerTriangle::getMinx(), vpTemplateTrackerTriangle::getMiny(), getNbTriangle(), getTriangle(), max_x, max_y, min_x, and min_y.

Referenced by vpTemplateTracker::initTrackingPyr(), and operator=().

◆ display() [1/2]

void vpTemplateTrackerZone::display ( const vpImage< unsigned char > &  I,
const vpColor col = vpColor::green,
unsigned int  thickness = 3 
)

If a display device is associated to image I, display in overlay the triangles that define the zone.

Parameters
I: Image.
col: Color used to display the triangles.
thickness: Thickness of the triangle lines.
Examples
templateTracker.cpp.

Definition at line 446 of file vpTemplateTrackerZone.cpp.

References vpDisplay::displayLine(), and Zone.

Referenced by vpTemplateTracker::display().

◆ display() [2/2]

void vpTemplateTrackerZone::display ( const vpImage< vpRGBa > &  I,
const vpColor col = vpColor::green,
unsigned int  thickness = 3 
)

If a display device is associated to image I, display in overlay the triangles that define the zone.

Parameters
I: Image.
col: Color used to display the triangles.
thickness: Thickness of the triangle lines.

Definition at line 463 of file vpTemplateTrackerZone.cpp.

References vpDisplay::displayLine(), and Zone.

◆ fillTriangle()

void vpTemplateTrackerZone::fillTriangle ( vpImage< unsigned char > &  I,
unsigned int  id,
unsigned char  gray_level 
)

Modify all the pixels inside a triangle with a given gray level.

Parameters
IOutput image.
idTriangle id. This value should be less than the number of triangles used to define the zone and available using getNbTriangle().
gray_levelColor used to fill the triangle with.

Definition at line 487 of file vpTemplateTrackerZone.cpp.

References vpImage< Type >::getHeight(), getNbTriangle(), getTriangle(), vpImage< Type >::getWidth(), and vpTemplateTrackerTriangle::inTriangle().

◆ getArea()

double vpTemplateTrackerZone::getArea ( ) const

Return the area of the template zone.

Definition at line 573 of file vpTemplateTrackerZone.cpp.

References vpTemplateTrackerTriangle::getArea(), getNbTriangle(), and getTriangle().

◆ getBoundingBox()

vpRect vpTemplateTrackerZone::getBoundingBox ( ) const

Return a rectangle that defines the bounding box of the zone.

See also
getMinx(), getMiny(), getMaxx(), getMaxy()

Definition at line 433 of file vpTemplateTrackerZone.cpp.

References max_x, max_y, min_x, min_y, vpRect::setBottomRight(), and vpRect::setTopLeft().

◆ getCenter() [1/2]

vpImagePoint vpTemplateTrackerZone::getCenter ( ) const

Return the position of the center of gravity of the zone.

Exceptions
vpException::divideByZeroErrorThe size of the zone is null.

Definition at line 386 of file vpTemplateTrackerZone.cpp.

References vpException::divideByZeroError, inZone(), max_x, max_y, min_x, min_y, and vpImagePoint::set_uv().

◆ getCenter() [2/2]

vpImagePoint vpTemplateTrackerZone::getCenter ( int  borne_x,
int  borne_y 
) const

Return the position of the center of gravity in a given area.

Parameters
borne_x: Right coordinate of the area to consider.
borne_y: Bottom coordinate of the area to consider.
Exceptions
vpException::divideByZeroErrorThe size of the zone is null.

Definition at line 547 of file vpTemplateTrackerZone.cpp.

References vpException::divideByZeroError, inZone(), and vpImagePoint::set_uv().

◆ getMaxx()

int vpTemplateTrackerZone::getMaxx ( ) const
Returns
The maximal x coordinate (along the columns of the image) of the points that are in the zone.
See also
getMinx(), getBoundingBox()

Definition at line 412 of file vpTemplateTrackerZone.cpp.

References max_x.

◆ getMaxy()

int vpTemplateTrackerZone::getMaxy ( ) const
Returns
The maximal y coordinate (along the rows of the image) of the points that are in the zone.
See also
getMiny(), getBoundingBox()

Definition at line 417 of file vpTemplateTrackerZone.cpp.

References max_y.

◆ getMinx()

int vpTemplateTrackerZone::getMinx ( ) const
Returns
The minimal x coordinate (along the columns of the image) of the points that are in the zone.
See also
getMaxx(), getBoundingBox()

Definition at line 422 of file vpTemplateTrackerZone.cpp.

References min_x.

◆ getMiny()

int vpTemplateTrackerZone::getMiny ( ) const
Returns
The minimal y coordinate (along the rows of the image) of the points that are in the zone.
See also
getMaxy(), getBoundingBox()

Definition at line 427 of file vpTemplateTrackerZone.cpp.

References min_y.

◆ getNbTriangle()

unsigned int vpTemplateTrackerZone::getNbTriangle ( ) const
inline

◆ getPyramidDown()

vpTemplateTrackerZone vpTemplateTrackerZone::getPyramidDown ( ) const

Return a zone with triangles that are down scaled by a factor 2.

Definition at line 504 of file vpTemplateTrackerZone.cpp.

References add(), getNbTriangle(), vpTemplateTrackerTriangle::getPyramidDown(), and getTriangle().

Referenced by vpTemplateTracker::initTrackingPyr().

◆ getTriangle() [1/2]

vpTemplateTrackerTriangle vpTemplateTrackerZone::getTriangle ( unsigned int  i) const

A zone is defined by a set of triangles. This function returns the ith triangle.

Parameters
i: Index of the triangle to return.
Returns
The triangle corresponding to index i.

The following sample code shows how to use this function:

...
for (unsigned int i=0; i < zone.getNbTriangle(); i++) {
}
void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const
unsigned int getNbTriangle() const

Definition at line 375 of file vpTemplateTrackerZone.cpp.

References vpException::badValue, getNbTriangle(), and Zone.

◆ getTriangle() [2/2]

void vpTemplateTrackerZone::getTriangle ( unsigned int  i,
vpTemplateTrackerTriangle T 
) const

A zone is defined by a set of triangles. This function returns the ith triangle.

Parameters
[in]i: Index of the triangle to return.
[out]T: The triangle corresponding to index i.
Exceptions
pException::badValueWhen the triangle with index i was not found.

The following sample code shows how to use this function:

...
for (unsigned int i=0; i < zone.getNbTriangle(); i++) {
zone.getTriangle(i, triangle);
}

Definition at line 354 of file vpTemplateTrackerZone.cpp.

References vpException::badValue, getNbTriangle(), and Zone.

Referenced by vpTemplateTracker::computeEvalRMS(), copy(), fillTriangle(), getArea(), getPyramidDown(), vpTemplateTracker::initPosEvalRMS(), and vpTemplateTrackerWarp::warpZone().

◆ initClick()

void vpTemplateTrackerZone::initClick ( const vpImage< unsigned char > &  I,
bool  delaunay = false 
)

Initialize a zone in image I using mouse click.

Parameters
I: Image used to select the zone.
delaunay: Flag used to enable Delaunay triangulation.
  • If true, from the image points selected by the user, a Delaunay triangulation is performed to initialize the zone.
    • A left click select a image point;
    • A right click select the last image point and ends the initialisation stage. In that case at least 3 points need to be selected by the user.
  • If false, the user select directly points as successive triangle corners. Three successive points define a triangle. It is not mandatory that triangles have one edge in common; they can define a discontinued area.
    • A left click select a triangle corner;
    • A right click select the last triangle corner and ends the initialisation stage. The number of points that are selected by the user should be a multiple of 3. For example, to select a zone as two triangles, the user has to left click five times and finish the selection on the sixth corner with a right click.

Definition at line 105 of file vpTemplateTrackerZone.cpp.

References vpColor::blue, vpMouseButton::button3, vpDisplay::displayCross(), vpDisplay::displayLine(), vpDisplay::flush(), vpDisplay::getClick(), initFromPoints(), vpColor::red, vpTime::wait(), and Zone.

Referenced by vpTemplateTracker::initClick().

◆ initFromPoints()

void vpTemplateTrackerZone::initFromPoints ( const vpImage< unsigned char > &  I,
const std::vector< vpImagePoint > &  vip,
bool  delaunay = false 
)

Initialize the zone using a vector of image points.

Parameters
I: Image to process.
vip: Vector of image points used as initialization.
delaunay:
  • If true, a Delaunay triangulation is perfomed on the vector of image points. This functionality is only available if ViSP is build with OpenCV >2.3 third-party.
  • If false, the vector of image points describe triangles. Its size is then a multiple of 3.

Definition at line 163 of file vpTemplateTrackerZone.cpp.

References add(), vpException::functionNotImplementedError, vpImage< Type >::getHeight(), vpTemplateTrackerTriangle::getMaxx(), vpTemplateTrackerTriangle::getMaxy(), vpTemplateTrackerTriangle::getMinx(), vpTemplateTrackerTriangle::getMiny(), vpImage< Type >::getWidth(), max_x, max_y, min_x, min_y, and Zone.

Referenced by initClick(), and vpTemplateTracker::initFromPoints().

◆ inZone() [1/4]

bool vpTemplateTrackerZone::inZone ( const double &  i,
const double &  j 
) const

Test if a pixel with coordinates (i,j) is in the zone..

Parameters
i,j: Coordinates of the pixel to test.
Returns
true if the pixel with coordinates (i,j) is in the zone defined by a set of triangles, false otherwise.

Definition at line 284 of file vpTemplateTrackerZone.cpp.

References Zone.

◆ inZone() [2/4]

bool vpTemplateTrackerZone::inZone ( const double &  i,
const double &  j,
unsigned int &  id_triangle 
) const

Test if a pixel with coordinates (i,j) is in the zone and returns also the index of the triangle that contains the pixel.

Parameters
i,j: Coordinates of the pixel to test.
id_triangle: Index of the triangle that contains the pixel (i,j).
Returns
true if the pixel with coordinates (i,j) is in the zone defined by a set of triangles, false otherwise.

Definition at line 322 of file vpTemplateTrackerZone.cpp.

References Zone.

◆ inZone() [3/4]

bool vpTemplateTrackerZone::inZone ( const int &  i,
const int &  j 
) const

Test if a pixel with coordinates (i,j) is in the zone..

Parameters
i,j: Coordinates of the pixel to test.
Returns
true if the pixel with coordinates (i,j) is in the zone defined by a set of triangles, false otherwise.

Definition at line 268 of file vpTemplateTrackerZone.cpp.

References Zone.

Referenced by getCenter(), and vpTemplateTracker::initTracking().

◆ inZone() [4/4]

bool vpTemplateTrackerZone::inZone ( const int &  i,
const int &  j,
unsigned int &  id_triangle 
) const

Test if a pixel with coordinates (i,j) is in the zone and returns also the index of the triangle that contains the pixel.

Parameters
i,j: Coordinates of the pixel to test.
id_triangle: Index of the triangle that contains the pixel (i,j).
Returns
true if the pixel with coordinates (i,j) is in the zone defined by a set of triangles, false otherwise.

Definition at line 301 of file vpTemplateTrackerZone.cpp.

References Zone.

◆ operator=()

vpTemplateTrackerZone & vpTemplateTrackerZone::operator= ( const vpTemplateTrackerZone z)

Copy operator.

Definition at line 75 of file vpTemplateTrackerZone.cpp.

References clear(), and copy().

Member Data Documentation

◆ max_x

int vpTemplateTrackerZone::max_x
protected

Bounding box parameter.

Definition at line 69 of file vpTemplateTrackerZone.h.

Referenced by add(), clear(), copy(), getBoundingBox(), getCenter(), getMaxx(), and initFromPoints().

◆ max_y

int vpTemplateTrackerZone::max_y
protected

Bounding box parameter.

Definition at line 70 of file vpTemplateTrackerZone.h.

Referenced by add(), clear(), copy(), getBoundingBox(), getCenter(), getMaxy(), and initFromPoints().

◆ min_x

int vpTemplateTrackerZone::min_x
protected

Bounding box parameter.

Definition at line 67 of file vpTemplateTrackerZone.h.

Referenced by add(), clear(), copy(), getBoundingBox(), getCenter(), getMinx(), and initFromPoints().

◆ min_y

int vpTemplateTrackerZone::min_y
protected

Bounding box parameter.

Definition at line 68 of file vpTemplateTrackerZone.h.

Referenced by add(), clear(), copy(), getBoundingBox(), getCenter(), getMiny(), and initFromPoints().

◆ Zone

std::vector<vpTemplateTrackerTriangle> vpTemplateTrackerZone::Zone
protected

Vector of triangles that defines the zone.

Definition at line 66 of file vpTemplateTrackerZone.h.

Referenced by add(), clear(), display(), getTriangle(), initClick(), initFromPoints(), and inZone().