Visual Servoing Platform  version 3.6.1 under development (2024-11-14)

#include <visp3/blob/vpDot.h>

+ Inheritance diagram for vpDot:

Public Types

enum  vpConnexityType { CONNEXITY_4 , CONNEXITY_8 }
 

Public Member Functions

 vpDot ()
 
VP_EXPLICIT vpDot (const vpImagePoint &ip)
 
 vpDot (const vpDot &d)
 
virtual ~vpDot () VP_OVERRIDE
 
void display (const vpImage< unsigned char > &I, vpColor color=vpColor::red, unsigned int thickness=1) const
 
vpColVector get_nij () const
 
double getArea () const
 
vpRect getBBox () const
 
vpImagePoint getCog () const
 
std::list< vpImagePointgetEdges () const
 
std::list< vpImagePointgetConnexities () const
 
double getGamma () const
 
double getGrayLevelPrecision () const
 
double getMaxDotSize () const
 
double getMeanGrayLevel () const
 
vpPolygon getPolygon () const
 
unsigned int getWidth () const
 
unsigned int getHeight () const
 
void initTracking (const vpImage< unsigned char > &I)
 
void initTracking (const vpImage< unsigned char > &I, const vpImagePoint &ip)
 
void initTracking (const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int gray_level_min, unsigned int gray_level_max)
 
vpDotoperator= (const vpDot &d)
 
bool operator== (const vpDot &d) const
 
bool operator!= (const vpDot &d) const
 
void print (std::ostream &os)
 
void setCog (const vpImagePoint &cog)
 
void setComputeMoments (bool activate)
 
void setConnexity (const vpConnexityType &connexityType)
 
void setMaxDotSize (double percentage)
 
void setGrayLevelMin (const unsigned int &level_min)
 
void setGrayLevelMax (const unsigned int &level_max)
 
void setGrayLevelPrecision (const double &grayLevelPrecision)
 
void setGraphics (bool activate)
 
void setGraphicsThickness (unsigned int thickness)
 
void track (const vpImage< unsigned char > &I)
 
void track (const vpImage< unsigned char > &I, vpImagePoint &ip)
 
Public Member Functions Inherited from vpTracker
vpColVector get_p () const
 
vpColVector get_cP () const
 

Static Public Member Functions

static void display (const vpImage< unsigned char > &I, const vpImagePoint &cog, const std::list< vpImagePoint > &edges_list, vpColor color=vpColor::red, unsigned int thickness=1)
 
static void display (const vpImage< vpRGBa > &I, const vpImagePoint &cog, const std::list< vpImagePoint > &edges_list, vpColor color=vpColor::red, unsigned int thickness=1)
 

Public Attributes

Public Attributes Inherited from vpTracker
vpColVector p
 
vpColVector cP
 
bool cPAvailable
 

Friends

VISP_EXPORT std::ostream & operator<< (std::ostream &os, vpDot &d)
 

Detailed Description

This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.

The underground algorithm is based on a binarization of the image and a connex component segmentation to determine the dot characteristics (location, moments, size...).

The following sample code shows how to grab images from a firewire camera, track a blob and display the tracking results.

#include <visp3/blob/vpDot.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/sensor/vp1394TwoGrabber.h>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
int main()
{
#if defined(VISP_HAVE_DC1394)
vpImage<unsigned char> I; // Create a gray level image container
vp1394TwoGrabber g(false); // Create a grabber based on libdc1394-2.x third party lib
g.acquire(I); // Acquire an image
#if defined(VISP_HAVE_X11)
vpDisplayX d(I, 0, 0, "Camera view");
#endif
vpDot blob;
blob.initTracking(I);
blob.setGraphics(true);
while(1) {
g.acquire(I); // Acquire an image
blob.track(I);
}
#endif
}
Class for firewire ieee1394 video devices using libdc1394-2.x api.
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
Definition: vpDot.h:116
void initTracking(const vpImage< unsigned char > &I)
Definition: vpDot.cpp:630
void setGraphics(bool activate)
Definition: vpDot.h:354
void track(const vpImage< unsigned char > &I)
Definition: vpDot.cpp:760
See also
vpDot2
Examples
poseVirtualVS.cpp, servoAfma4Point2DArtVelocity.cpp, servoAfma4Point2DCamVelocity.cpp, servoAfma6Ellipse2DCamVelocity.cpp, servoAfma6Point2DArtVelocity.cpp, servoAfma6Point2DCamVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, servoAfma6Segment2DCamVelocity.cpp, servoViper850FourPoints2DArtVelocityLs_des.cpp, testRobotAfma6Pose.cpp, testRobotViper850Pose.cpp, and trackDot.cpp.

Definition at line 115 of file vpDot.h.

Member Enumeration Documentation

◆ vpConnexityType

Type of connexity 4, or 8.

Enumerator
CONNEXITY_4 

For a given pixel 4 neighbors are considered (left, right, up, down)

CONNEXITY_8 

For a given pixel 8 neighbors are considered (left, right, up, down, and the 4 pixels located on the diagonal)

Definition at line 121 of file vpDot.h.

Constructor & Destructor Documentation

◆ vpDot() [1/3]

vpDot::vpDot ( )

Definition at line 100 of file vpDot.cpp.

◆ vpDot() [2/3]

vpDot::vpDot ( const vpImagePoint cog)

Constructor with initialization of the dot location.

Parameters
cog: An image point with sub-pixel coordinates corresponding to the blob center of gravity.

Definition at line 117 of file vpDot.cpp.

◆ vpDot() [3/3]

vpDot::vpDot ( const vpDot d)

Copy constructor.

Definition at line 132 of file vpDot.cpp.

◆ ~vpDot()

vpDot::~vpDot ( )
virtual

Destructor.

Definition at line 145 of file vpDot.cpp.

Member Function Documentation

◆ display() [1/3]

void vpDot::display ( const vpImage< unsigned char > &  I,
const vpImagePoint cog,
const std::list< vpImagePoint > &  edges_list,
vpColor  color = vpColor::red,
unsigned int  thickness = 1 
)
static

Display the dot center of gravity and its list of edges.

Parameters
I: The image used as background.
cog: The center of gravity.
edges_list: The list of edges;
color: Color used to display the dot.
thickness: Thickness of the dot.

Definition at line 872 of file vpDot.cpp.

References vpDisplay::displayCross(), and vpDisplay::displayPoint().

◆ display() [2/3]

void vpDot::display ( const vpImage< unsigned char > &  I,
vpColor  color = vpColor::red,
unsigned int  thick = 1 
) const

Display in overlay the dot edges and center of gravity.

Parameters
I: Image.
color: The color used for the display.
thick: Thickness of the displayed cross located at the dot cog.

Definition at line 813 of file vpDot.cpp.

References vpDisplay::displayCross(), and vpDisplay::displayPoint().

◆ display() [3/3]

void vpDot::display ( const vpImage< vpRGBa > &  I,
const vpImagePoint cog,
const std::list< vpImagePoint > &  edges_list,
vpColor  color = vpColor::red,
unsigned int  thickness = 1 
)
static

Display the dot center of gravity and its list of edges.

Parameters
I: The image used as background.
cog: The center of gravity.
edges_list: The list of edges;
color: Color used to display the dot.
thickness: Thickness of the dot.

Definition at line 900 of file vpDot.cpp.

References vpDisplay::displayCross(), and vpDisplay::displayPoint().

◆ get_cP()

vpColVector vpTracker::get_cP ( ) const
inlineinherited

Return object parameters expressed in the 3D camera frame.

Definition at line 95 of file vpTracker.h.

◆ get_nij()

vpColVector vpDot::get_nij ( ) const
inline

Gets the second order normalized centered moment $ n_{ij} $ as a 3-dim vector containing $ n_{20}, n_{11}, n_{02} $ such as $ n_{ij} = \mu_{ij}/m_{00} $

Returns
The 3-dim vector containing $ n_{20}, n_{11}, n_{02} $.
See also
getCog(), getArea()

Definition at line 209 of file vpDot.h.

◆ get_p()

vpColVector vpTracker::get_p ( ) const
inlineinherited

Return object parameters expressed in the 2D image plane computed by perspective projection.

Definition at line 93 of file vpTracker.h.

◆ getArea()

double vpDot::getArea ( ) const
inline

Gets the area of the blob corresponding also to the zero order moment.

Returns
The blob area.

Definition at line 227 of file vpDot.h.

◆ getBBox()

vpRect vpDot::getBBox ( ) const
inline

Return the dot bounding box.

See also
getWidth(), getHeight()

Definition at line 234 of file vpDot.h.

References vpRect::setRect().

◆ getCog()

◆ getConnexities()

std::list<vpImagePoint> vpDot::getConnexities ( ) const
inline

Return the list of all the image points inside the dot.

Returns
The list of all the images points in the dot. This list is updated after a call to track().

Definition at line 263 of file vpDot.h.

◆ getEdges()

std::list<vpImagePoint> vpDot::getEdges ( ) const
inline

Return the list of all the image points on the border of the dot.

Warning
Doesn't return the image points inside the dot anymore. To get those points see getConnexities().

Definition at line 255 of file vpDot.h.

◆ getGamma()

double vpDot::getGamma ( ) const
inline

Definition at line 265 of file vpDot.h.

◆ getGrayLevelPrecision()

double vpDot::getGrayLevelPrecision ( ) const
inline

Return the precision of the gray level of the dot. It is a double precision float witch value is in ]0,1]. 1 means full precision, whereas values close to 0 show a very bad precision.

Definition at line 272 of file vpDot.h.

◆ getHeight()

unsigned int vpDot::getHeight ( ) const
inline

Return the width of the dot.

See also
getHeight()

Definition at line 297 of file vpDot.h.

◆ getMaxDotSize()

double vpDot::getMaxDotSize ( ) const
inline

Definition at line 273 of file vpDot.h.

◆ getMeanGrayLevel()

double vpDot::getMeanGrayLevel ( ) const
inline

Return the mean gray level value of the dot.

Definition at line 278 of file vpDot.h.

◆ getPolygon()

vpPolygon vpDot::getPolygon ( ) const
inline
Returns
a vpPolygon made from the edges of the dot.

Definition at line 283 of file vpDot.h.

◆ getWidth()

unsigned int vpDot::getWidth ( ) const
inline

Return the width of the dot.

See also
getHeight()

Definition at line 290 of file vpDot.h.

◆ initTracking() [1/3]

void vpDot::initTracking ( const vpImage< unsigned char > &  I)

Initialize the tracking with a mouse click and update the dot characteristics (center of gravity, moments).

Wait a user click in a gray area in the image I. The clicked pixel will be the starting point from which the dot will be tracked.

The threshold used to segment the dot is set with the gray level precision parameter. See the formula in setGrayLevelPrecision() function.

The sub pixel coordinates of the dot are updated. To get the center of gravity coordinates of the dot, use getCog(). To compute the moments use setComputeMoments(true) before a call to initTracking().

Warning
The content of the image modified since we call track() to compute the dot characteristics.
Parameters
I: Image to process.
See also
track(), getCog()
Examples
servoAfma4Point2DArtVelocity.cpp, servoAfma4Point2DCamVelocity.cpp, servoAfma6Ellipse2DCamVelocity.cpp, servoAfma6Point2DArtVelocity.cpp, servoAfma6Point2DCamVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, servoViper850FourPoints2DArtVelocityLs_des.cpp, testRobotAfma6Pose.cpp, and testRobotViper850Pose.cpp.

Definition at line 630 of file vpDot.cpp.

References vpImagePoint::get_i(), vpImagePoint::get_j(), vpDisplay::getClick(), and track().

◆ initTracking() [2/3]

void vpDot::initTracking ( const vpImage< unsigned char > &  I,
const vpImagePoint ip 
)

Initialize the tracking for a dot supposed to be located at (u,v) and updates the dot characteristics (center of gravity, moments).

The threshold used to segment the dot is set to 80 percent of the gray level of the pixel (u,v).

The sub pixel coordinates of the dot are updated. To get the center of gravity coordinates of the dot, use getCog(). To compute the moments use setComputeMoments(true) before a call to initTracking().

Warning
The content of the image modified since we call track() to compute the dot characteristics.
Parameters
I: Image to process.
ip: Location of the starting point from which the dot will be tracked in the image.
See also
track()

Definition at line 682 of file vpDot.cpp.

References vpImagePoint::get_i(), vpImagePoint::get_j(), and track().

◆ initTracking() [3/3]

void vpDot::initTracking ( const vpImage< unsigned char > &  I,
const vpImagePoint ip,
unsigned int  level_min,
unsigned int  level_max 
)

Initialize the tracking for a dot supposed to be located at (u,v) and updates the dot characteristics (center of gravity, moments).

The sub pixel coordinates of the dot are updated. To get the center of gravity coordinates of the dot, use getCog(). To compute the moments use setComputeMoments(true) before a call to initTracking().

Warning
The content of the image modified since we call track() to compute the dot characteristics.
Parameters
I: Image to process.
ip: Location of the starting point from which the dot will be tracked in the image.
level_min: Minimum gray level threshold used to segment the dot; value comprised between 0 and 255.
level_max: Maximum gray level threshold used to segment the dot; value comprised between 0 and 255. gray_level_max should be greater than gray_level_min.
See also
track(), getCog()

Definition at line 735 of file vpDot.cpp.

References track().

◆ operator!=()

bool vpDot::operator!= ( const vpDot d) const

Definition at line 188 of file vpDot.cpp.

◆ operator=()

vpDot & vpDot::operator= ( const vpDot d)

Copy operator.

Definition at line 150 of file vpDot.cpp.

◆ operator==()

bool vpDot::operator== ( const vpDot d) const

Definition at line 190 of file vpDot.cpp.

◆ print()

void vpDot::print ( std::ostream &  os)
inline

Definition at line 309 of file vpDot.h.

◆ setCog()

void vpDot::setCog ( const vpImagePoint cog)
inline

Initialize the dot center of gravity coordinates with cog.

Definition at line 314 of file vpDot.h.

◆ setComputeMoments()

void vpDot::setComputeMoments ( bool  activate)
inline

Activates the dot's moments computation.

Parameters
activatetrue, if you want to compute the moments. If false, moments are not computed.

Computed moment are vpDot::m00, vpDot::m10, vpDot::m01, vpDot::m11, vpDot::m20, vpDot::m02 and second order centered moments vpDot::mu11, vpDot::mu20, vpDot::mu02 computed with respect to the blob centroid.

The coordinates of the region's centroid (u, v) can be computed from the moments by $u=\frac{m10}{m00}$ and $v=\frac{m01}{m00}$.

Examples
servoAfma6Ellipse2DCamVelocity.cpp.

Definition at line 329 of file vpDot.h.

◆ setConnexity()

void vpDot::setConnexity ( const vpConnexityType connexityType)
inline

Set the type of connexity: 4 or 8.

Definition at line 334 of file vpDot.h.

◆ setGraphics()

void vpDot::setGraphics ( bool  activate)
inline

Activates the display of all the pixels of the dot during the tracking. The default thickness of the overlayed drawings can be modified using setGraphicsThickness().

Warning
To effectively display the dot graphics a call to vpDisplay::flush() is needed.
Parameters
activatetrue to activate the display of dot pixels, false to turn off the display.
See also
setGraphicsThickness()
Examples
servoAfma6Point2DArtVelocity.cpp, servoAfma6Point2DCamVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, servoViper850FourPoints2DArtVelocityLs_des.cpp, testRobotAfma6Pose.cpp, and testRobotViper850Pose.cpp.

Definition at line 354 of file vpDot.h.

◆ setGraphicsThickness()

void vpDot::setGraphicsThickness ( unsigned int  thickness)
inline

Modify the default thickness that is set to 1 of the drawings in overlay when setGraphics() is enabled.

See also
setGraphics()

Definition at line 361 of file vpDot.h.

◆ setGrayLevelMax()

void vpDot::setGrayLevelMax ( const unsigned int &  level_max)
inline

Definition at line 337 of file vpDot.h.

◆ setGrayLevelMin()

void vpDot::setGrayLevelMin ( const unsigned int &  level_min)
inline

Definition at line 336 of file vpDot.h.

◆ setGrayLevelPrecision()

void vpDot::setGrayLevelPrecision ( const double &  precision)

Set the precision of the gray level of the dot.

Parameters
precision: It is a double precision float which value is in ]0,1]:
  • 1 means full precision, whereas values close to 0 show a very bad accuracy.
  • Values lower or equal to 0 are brought back to an epsilon>0
  • Values higher than 1 are brought back to 1 If the initial gray level is I, the gray levels of the dot will be between : $Imin=255*\big((\frac{I}{255})^{{\gamma}^{-1}}-(1-grayLevelPrecision)\big)^{\gamma}$ and $Imax=255*\big((\frac{I}{255})^{{\gamma}^{-1}}+(1-grayLevelPrecision)\big)^{\gamma}$ with $\gamma=1.5$ .
See also
setWidth(), setHeight(), setGrayLevelMin(), setGrayLevelMax()

Definition at line 844 of file vpDot.cpp.

◆ setMaxDotSize()

void vpDot::setMaxDotSize ( double  percentage)

Maximal size of the region to track in terms of image size percentage.

Parameters
percentage: Image size percentage corresponding to the dot maximal size. Values should be in ]0 : 1]. If 1, that means that the dot to track could take up the whole image.

During the tracking, if the dot size if bigger than the maximal size allowed an exception is throwed : vpTrackingException::featureLostError.

Examples
servoAfma6Ellipse2DCamVelocity.cpp.

Definition at line 595 of file vpDot.cpp.

◆ track() [1/2]

void vpDot::track ( const vpImage< unsigned char > &  I)

Track and compute the dot characteristics.

To get the center of gravity coordinates of the dot, use getCog(). To compute the moments use setComputeMoments(true) before a call to initTracking().

Warning
The image is modified (all the pixels that belong to the point are set to white (ie to 255).
Parameters
I: Image to process.
See also
getCog()
Examples
servoAfma4Point2DArtVelocity.cpp, servoAfma4Point2DCamVelocity.cpp, servoAfma6Ellipse2DCamVelocity.cpp, servoAfma6Point2DArtVelocity.cpp, servoAfma6Point2DCamVelocity.cpp, servoAfma6Points2DCamVelocityEyeToHand.cpp, and servoViper850FourPoints2DArtVelocityLs_des.cpp.

Definition at line 760 of file vpDot.cpp.

References vpDisplay::displayCross(), vpImagePoint::get_u(), vpImagePoint::get_v(), vpColor::red, vpImagePoint::set_u(), and vpImagePoint::set_v().

Referenced by initTracking(), and track().

◆ track() [2/2]

void vpDot::track ( const vpImage< unsigned char > &  I,
vpImagePoint ip 
)

Track and updates the new dot coordinates

To compute the moments use setComputeMoments(true) before a call to initTracking() or track().

Warning
The image is modified (all the pixels that belong to the point are set to white (ie to 255).
Parameters
I: Image to process.
ip[out] : Sub pixel coordinate of the tracked dot center of gravity.

Definition at line 799 of file vpDot.cpp.

References track().

Friends And Related Function Documentation

◆ operator<<

VISP_EXPORT std::ostream& operator<< ( std::ostream &  os,
vpDot d 
)
friend

Writes the dot center of gravity coordinates in the frame (i,j) (For more details about the orientation of the frame see the vpImagePoint documentation) to the stream os, and returns a reference to the stream.

Definition at line 919 of file vpDot.cpp.

Member Data Documentation

◆ cP

◆ cPAvailable

bool vpTracker::cPAvailable
inherited

Flag used to indicate if the feature parameters cP expressed in the camera frame are available.

Definition at line 79 of file vpTracker.h.

Referenced by vpTracker::init(), and vpTracker::operator=().

◆ p