Visual Servoing Platform  version 3.3.0
vpMomentCentered Class Reference

#include <vpMomentCentered.h>

+ Inheritance diagram for vpMomentCentered:

Public Member Functions

 vpMomentCentered ()
 
virtual ~vpMomentCentered ()
 
void compute ()
 
double get (unsigned int i, unsigned int j) const
 
const std::vector< double > & get () const
 
const char * name () const
 
void printWithIndices (std::ostream &os) const
 
void printDependencies (std::ostream &os) const
 
Inherited functionalities from vpMoment
const vpMomentObjectgetObject () const
 
void linkTo (vpMomentDatabase &moments)
 
void update (vpMomentObject &object)
 

Protected Member Functions

void set (unsigned int i, unsigned int j, double value)
 
vpMomentDatabasegetMoments () const
 

Protected Attributes

std::vector< double > values
 

Friends

VISP_EXPORT std::ostream & operator<< (std::ostream &os, const vpMomentCentered &v)
 

Detailed Description

This class defines the double-indexed centered moment descriptor $\mu_{ij}$.

In the case of a dense object O, centered moments are defined by:

\[\mu_{ij}= \int \int_{O} (x_k-x_g)^j (y_k-y_g)^j\]

In the case of a discrete set of n points, centered moments are defined by:

\[\mu_{ij}= \sum_{k=1}^{n} (x_k-x_g)^j (y_k-y_g)^j\]

where $(x_g,y_g)$ are the coordinates of the center of gravity.

The centered moments are computed from the object at the highest possible order. For example if the vpMomentObject is defined up to order 5, vpMomentCentered will be too.

Values of vpMomentCentered may be accessed by one of the two vpMomentCentered::get methods. When using vpMomentCentered::get (), the format of the return vector is the following: $ \mu_{ij} $ is stored at vpMomentCentered::get ()[j* (vpMomentObject::getOrder () +1)+i]

vpMomentCentered depends on vpMomentGravityCenter.

Examples
mbot-apriltag-ibvs.cpp, servoBebop2.cpp, and testMomentAlpha.cpp.

Definition at line 78 of file vpMomentCentered.h.

Constructor & Destructor Documentation

◆ vpMomentCentered()

vpMomentCentered::vpMomentCentered ( )

Default constructor.

Definition at line 94 of file vpMomentCentered.cpp.

◆ ~vpMomentCentered()

virtual vpMomentCentered::~vpMomentCentered ( )
inlinevirtual

Definition at line 82 of file vpMomentCentered.h.

Member Function Documentation

◆ compute()

void vpMomentCentered::compute ( )
virtual

Computes centered moments of all available orders. Depends on vpMomentGravityCenter.

Implements vpMoment.

Examples
mbot-apriltag-ibvs.cpp, servoBebop2.cpp, and testMomentAlpha.cpp.

Definition at line 64 of file vpMomentCentered.cpp.

◆ get() [1/2]

const std::vector< double > & vpMomentCentered::get ( ) const
inline

Returns all centered moment values $\mu_{ij}$ with $i+j \leq order$ where order is the object's order.

Returns
Vector of moment values. To access $\mu_{ij}$, you have to read vpMomentObject::get()[j*order+i].

For example, if the maximal order is 3, the following values are provided:

u00 u10 u20 u01 u11 u21 u02 u12 u12 u30 u03

To have a better reading of the moments you can picture them as a triangular matrix:

u00 u10 u20 u30 u01 u11 u21 x u02 u12 x x u30 x x x

The moments of the same order are on each of the matrix reverse diagonals. To access for example to the centered moment $\mu_{12}$, you should use this kind of code:

//[...]
mc.compute();
double mu12;
mu12 = mc.get()[2*(obj.getOrder()+1)+1]; // i=1 and j=2
mu12 = mc.get(1,2); // the same

Definition at line 134 of file vpMomentCentered.h.

◆ get() [2/2]

double vpMomentCentered::get ( unsigned int  i,
unsigned int  j 
) const

Gets the desired moment using indexes.

Parameters
i: first index of the centered moment.
j: second index of the centered moment.
Returns
$\mu_{ij}$ moment.
Examples
testMomentAlpha.cpp.

Definition at line 102 of file vpMomentCentered.cpp.

◆ getMoments()

vpMomentDatabase& vpMoment::getMoments ( ) const
inlineprotectedinherited

Returns the linked moment database.

Returns
the moment database

Definition at line 122 of file vpMoment.h.

◆ getObject()

const vpMomentObject& vpMoment::getObject ( ) const
inlineinherited

Definition at line 149 of file vpMoment.h.

◆ linkTo()

void vpMoment::linkTo ( vpMomentDatabase data_base)
inherited

Links the moment to a database of moment primitives. If the moment depends on other moments, these moments must be linked to the same database.

Attention
Two moments of the same class cannot be stored in the same database
#include <visp3/core/vpMomentCentered.h>
#include <visp3/core/vpMomentDatabase.h>
#include <visp3/core/vpMomentGravityCenter.h>
#include <visp3/core/vpMomentObject.h>
#include <visp3/core/vpPoint.h>
int main()
{
std::vector<vpPoint> vec_p;
p.set_x(1); p.set_y(1); // coordinates in meters in the image plane (vertex 1)
vec_p.push_back(p); p.set_x(2); p.set_y(2); // coordinates in meters in the image plane (vertex 2)
obj.setType(vpMomentObject::DISCRETE); // Discrete mode.
obj.fromVector(vec_p); // Init the dense object with the polygon
vpMomentGravityCenter G; // declaration of gravity center
vpMomentCentered mc; // mc contains centered moments
G.linkTo(db); //add gravity center to database
mc.linkTo(db); //centered moments depend on gravity, add them to the
//database to grant access
G.update(obj); // specify the object for gravity center
mc.update(obj); // and for centered moments
G.compute(); // compute the moment
mc.compute(); //compute centered moments AFTER gravity center
return 0;
}
Parameters
data_base: database of moment primitives.
Examples
mbot-apriltag-ibvs.cpp, servoBebop2.cpp, and testMomentAlpha.cpp.

Definition at line 97 of file vpMoment.cpp.

◆ name()

const char* vpMomentCentered::name ( ) const
inlinevirtual

Moment name.

Implements vpMoment.

Definition at line 91 of file vpMomentCentered.h.

◆ printDependencies()

void vpMomentCentered::printDependencies ( std::ostream &  os) const
virtual

Prints moments required for calculation of vpMomentCentered, which are

  1. Raw geometric moments (vpMomentObject) and
  2. Centre of gravity (vpMomentGravityCentered)

Reimplemented from vpMoment.

Definition at line 171 of file vpMomentCentered.cpp.

◆ printWithIndices()

void vpMomentCentered::printWithIndices ( std::ostream &  os) const

Print in a readable form which looks better than output from << operator

Definition at line 153 of file vpMomentCentered.cpp.

◆ set()

void vpMomentCentered::set ( unsigned int  i,
unsigned int  j,
double  value 
)
protected

To set the values of centred moments. Required when normalizing the moment values.

Parameters
i: first index of the 2D moment.
j: second index of the 2D moment.
value: value of the moment.

Definition at line 51 of file vpMomentCentered.cpp.

◆ update()

void vpMoment::update ( vpMomentObject moment_object)
inherited

Updates the moment with the current object. This does not compute any values.

Parameters
moment_object: object descriptor of the current camera vision.

Definition at line 114 of file vpMoment.cpp.

Friends And Related Function Documentation

◆ operator<<

VISP_EXPORT std::ostream& operator<< ( std::ostream &  os,
const vpMomentCentered v 
)
friend

Outputs the centered moment's values $\mu_{ij}$ to a stream presented as a matrix. The first line corresponds to $\mu_{0[0:order]}$, the second one to $\mu_{1[0:order]}$ Values in table corresponding to a higher order are marked with an "x" and not computed.

For example, if the maximal order is 3, the following values are provided:

u00 u10 u20 u30
u01 u11 u21 x
u02 u12 x x
u30 x x x

This output will be followed by an output with indexes as produced by printWithIndices() function

Definition at line 132 of file vpMomentCentered.cpp.

Member Data Documentation

◆ values

std::vector<double> vpMoment::values
protectedinherited

Definition at line 117 of file vpMoment.h.

vpMoment::linkTo
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:97
vpMomentCentered
This class defines the double-indexed centered moment descriptor .
Definition: vpMomentCentered.h:78
vpMomentGravityCenter::compute
void compute()
Definition: vpMomentGravityCenter.cpp:44
vpMomentDatabase
This class allows to register all vpMoments so they can access each other according to their dependen...
Definition: vpMomentDatabase.h:130
vpMomentCentered::get
double get(unsigned int i, unsigned int j) const
Definition: vpMomentCentered.cpp:102
vpMomentObject::DISCRETE
Definition: vpMomentObject.h:230
vpMoment::update
void update(vpMomentObject &object)
Definition: vpMoment.cpp:114
vpPoint::set_y
void set_y(double y)
Set the point y coordinate in the image plane.
Definition: vpPoint.cpp:473
vpMomentObject
Class for generic objects.
Definition: vpMomentObject.h:218
vpMomentCentered::compute
void compute()
Definition: vpMomentCentered.cpp:64
vpPoint
Class that defines what is a point.
Definition: vpPoint.h:57
vpPoint::set_x
void set_x(double x)
Set the point x coordinate in the image plane.
Definition: vpPoint.cpp:471
vpMomentGravityCenter
Class describing 2D gravity center moment.
Definition: vpMomentGravityCenter.h:112