Visual Servoing Platform  version 3.2.0
vpMomentCInvariant Class Reference

#include <vpMomentCInvariant.h>

+ Inheritance diagram for vpMomentCInvariant:

Public Member Functions

 vpMomentCInvariant (bool flg_sxsynormalization=false)
 
virtual ~vpMomentCInvariant ()
 
double C1 () const
 
double C2 () const
 
double C3 () const
 
double C4 () const
 
double C5 () const
 
double C6 () const
 
double C7 () const
 
double C8 () const
 
double C9 () const
 
double C10 () const
 
void compute ()
 
double get (unsigned int i) const
 
double getC (unsigned int i) const
 
double getI (unsigned int index) const
 
void printInvariants (std::ostream &os) const
 
double getII (unsigned int i) const
 
double getK () const
 
double getS (unsigned int i) const
 
const char * name () const
 
void printI (unsigned int index)
 
double Px ()
 
double Py ()
 
double Sx () const
 
double Sy () const
 
double getIn1 () const
 
double getCN (unsigned int i) const
 
double getSN (unsigned int i) const
 
bool isSxSyfromNormalizedMoments () const
 
const std::vector< double > & getMomentVector () const
 
Inherited functionalities from vpMoment
const vpMomentObjectgetObject () const
 
const std::vector< double > & get () const
 
void linkTo (vpMomentDatabase &moments)
 
virtual void printDependencies (std::ostream &os) const
 
void update (vpMomentObject &object)
 

Protected Member Functions

vpMomentDatabasegetMoments () const
 

Protected Attributes

std::vector< double > values
 

Friends

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

Detailed Description

This class defines several 2D (translation+rotation+scale) invariants for both symmetric and non-symmetric objects. These moment-based invariants are described in the following papers [Chaumette04a], [Tahri05z].

The descriptions for the invariants $C_1$ to $C_{10}$ can be found in [Chaumette04a] and for invariants $P_x$, $P_y$, $S_x$, $S_y$ in [Tahri05z].

These invariants are classicaly used in visual servoing to control the out-of-plane rotations. The C-type or P-type invariants are used for non-symmetric objects whereas the S-type invariants are used for symmetric objects.

For most cases of non-symmetric objects, ( $C_4$, $C_6$) or ( $P_x$, $P_y$) couples are widely used to control x and y rotations. For symmetric objects $S_x$ and $S_y$ are the only choice.

There are 14 translation+rotation+scale invariants (10 C-type, 2 P-type and 2 S-type) that can be accessed from by vpMomentCInvariant::get or any of the get shortcuts.

The example below shows how to retrieve the $C_2$ invariant:

#include <visp3/core/vpMomentObject.h>
#include <visp3/core/vpPoint.h>
#include <visp3/core/vpMomentCInvariant.h>
#include <visp3/core/vpMomentCommon.h>
#include <iostream>
int main()
{
std::vector<vpPoint> vec_p;
p.set_x(6); 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(3); // coordinates in meters in the image plane (vertex 2)
vec_p.push_back(p);
p.set_x(0); p.set_y(1.2); // coordinates in meters in the image plane (vertex 1)
vec_p.push_back(p);
p.set_x(-7); p.set_y(-4); // coordinates in meters in the image plane (vertex 2)
vec_p.push_back(p);
vpMomentObject obj(5); // Create an image moment object with 5 as maximum order
obj.setType(vpMomentObject::DISCRETE); // Discrete mode for object
obj.fromVector(vec_p);
//initialisation with default values
bool success;
db.updateAll(obj); // Update AND compute all moments
//get C-invariant
= static_cast<const vpMomentCInvariant&>(db.get("vpMomentCInvariant",success));
if(success)
std::cout << C.get(1) << std:: endl; // print C2 invariant
else
std::cout << "vpMomentCInvariant not found." << std::endl;
return 0;
}

vpMomentCInvariant depends on vpMomentCentered (see vpMomentDatabase and vpMomentCommon).

Definition at line 126 of file vpMomentCInvariant.h.

Constructor & Destructor Documentation

◆ vpMomentCInvariant()

vpMomentCInvariant::vpMomentCInvariant ( bool  flg_sxsynormalization = false)
explicit

Default constructor. (option to use a different calculation mode for sx and sy)

Definition at line 47 of file vpMomentCInvariant.cpp.

◆ ~vpMomentCInvariant()

virtual vpMomentCInvariant::~vpMomentCInvariant ( )
inlinevirtual

Definition at line 147 of file vpMomentCInvariant.h.

Member Function Documentation

◆ C1()

double vpMomentCInvariant::C1 ( ) const
inline

Shorcut for getting the value of $C_1$.

Definition at line 152 of file vpMomentCInvariant.h.

◆ C10()

double vpMomentCInvariant::C10 ( ) const
inline

Shorcut for getting the value of $C_{10}$.

Definition at line 188 of file vpMomentCInvariant.h.

◆ C2()

double vpMomentCInvariant::C2 ( ) const
inline

Shorcut for getting the value of $C_2$.

Definition at line 156 of file vpMomentCInvariant.h.

◆ C3()

double vpMomentCInvariant::C3 ( ) const
inline

Shorcut for getting the value of $C_3$.

Definition at line 160 of file vpMomentCInvariant.h.

◆ C4()

double vpMomentCInvariant::C4 ( ) const
inline

Shorcut for getting the value of $C_4$.

Definition at line 164 of file vpMomentCInvariant.h.

◆ C5()

double vpMomentCInvariant::C5 ( ) const
inline

Shorcut for getting the value of $C_5$.

Definition at line 168 of file vpMomentCInvariant.h.

◆ C6()

double vpMomentCInvariant::C6 ( ) const
inline

Shorcut for getting the value of $C_6$.

Definition at line 172 of file vpMomentCInvariant.h.

◆ C7()

double vpMomentCInvariant::C7 ( ) const
inline

Shorcut for getting the value of $C_7$.

Definition at line 176 of file vpMomentCInvariant.h.

◆ C8()

double vpMomentCInvariant::C8 ( ) const
inline

Shorcut for getting the value of $C_8$.

Definition at line 180 of file vpMomentCInvariant.h.

◆ C9()

double vpMomentCInvariant::C9 ( ) const
inline

Shorcut for getting the value of $C_9$.

Definition at line 184 of file vpMomentCInvariant.h.

◆ compute()

void vpMomentCInvariant::compute ( )
virtual

Computes translation-plane-rotation-scale invariants. Depends on vpMomentCentered. All possible invariants are computed here. The selection of the invariant is done afterwards.

Implements vpMoment.

Definition at line 194 of file vpMomentCInvariant.cpp.

◆ get() [1/2]

const std::vector<double>& vpMoment::get ( ) const
inlineinherited

Returns all values computed by the moment.

Returns
vector of values

Definition at line 154 of file vpMoment.h.

◆ get() [2/2]

double vpMomentCInvariant::get ( unsigned int  i) const
inline

Gets the desired invariant.

Parameters
igiven index. For invariants from C1 to C10 the corresponding index is from 0 to 9. For $S_x$, $S_y$ the indexes are 10,11 and for $P_x$, $P_y$ they are 12,13.

Definition at line 198 of file vpMomentCInvariant.h.

◆ getC()

double vpMomentCInvariant::getC ( unsigned int  i) const
inline

Access to partial invariant c (see [2]).

Definition at line 203 of file vpMomentCInvariant.h.

◆ getCN()

double vpMomentCInvariant::getCN ( unsigned int  i) const
inline

Getter for c (calculated from normalized 2nd and 3ord order moments)

Definition at line 266 of file vpMomentCInvariant.h.

◆ getI()

double vpMomentCInvariant::getI ( unsigned int  index) const
inline

Access to partial invariants. The index convention is the same as in [1].

Definition at line 207 of file vpMomentCInvariant.h.

◆ getII()

double vpMomentCInvariant::getII ( unsigned int  i) const
inline

Access to partial invariant I (see [2]).

Definition at line 217 of file vpMomentCInvariant.h.

◆ getIn1()

double vpMomentCInvariant::getIn1 ( ) const
inline

Getters for I (calculated from normalized 2nd and 3ord order moments)

Definition at line 260 of file vpMomentCInvariant.h.

◆ getK()

double vpMomentCInvariant::getK ( ) const
inline

Access to partial invariant K (see [2]).

Definition at line 221 of file vpMomentCInvariant.h.

◆ getMoments()

vpMomentDatabase& vpMoment::getMoments ( ) const
inlineprotectedinherited

Returns the linked moment database.

Returns
the moment database

Definition at line 122 of file vpMoment.h.

◆ getMomentVector()

const std::vector<double>& vpMomentCInvariant::getMomentVector ( ) const
inline

To get all the invariant values as a whole.

Definition at line 282 of file vpMomentCInvariant.h.

◆ getObject()

const vpMomentObject& vpMoment::getObject ( ) const
inlineinherited

Definition at line 149 of file vpMoment.h.

◆ getS()

double vpMomentCInvariant::getS ( unsigned int  i) const
inline

Access to partial invariant S (see [2]).

Definition at line 226 of file vpMomentCInvariant.h.

◆ getSN()

double vpMomentCInvariant::getSN ( unsigned int  i) const
inline

Getter for s (calculated from normalized 2nd and 3ord order moments)

Definition at line 272 of file vpMomentCInvariant.h.

◆ isSxSyfromNormalizedMoments()

bool vpMomentCInvariant::isSxSyfromNormalizedMoments ( ) const
inline

To know if Sx and Sy were calculated from normalized moments or not

Definition at line 277 of file vpMomentCInvariant.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 containts 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, and testMomentAlpha.cpp.

Definition at line 97 of file vpMoment.cpp.

◆ name()

const char* vpMomentCInvariant::name ( ) const
inlinevirtual

Moment name.

Implements vpMoment.

Definition at line 231 of file vpMomentCInvariant.h.

◆ printDependencies()

void vpMoment::printDependencies ( std::ostream &  os) const
virtualinherited

Prints values of all dependent moments required to calculate a specific vpMoment. Not made pure to maintain compatibility Recommended : Types inheriting from vpMoment should implement this function

Reimplemented in vpMomentAlpha, vpMomentAreaNormalized, vpMomentGravityCenter, vpMomentCentered, vpMomentBasic, vpMomentGravityCenterNormalized, and vpMomentArea.

Definition at line 134 of file vpMoment.cpp.

◆ printI()

void vpMomentCInvariant::printI ( unsigned int  index)

Print partial invariant.

Prints the temporary invariants. Used for debug purposes only

Parameters
index: index of the temporary invariant

Definition at line 268 of file vpMomentCInvariant.cpp.

◆ printInvariants()

void vpMomentCInvariant::printInvariants ( std::ostream &  os) const

Print the moment invariants used to obtain the actual visual features

Print out all invariants that were computed There are 15 of them, as in [Point-based and region based.ITRO05] [Tahri05z]

Definition at line 275 of file vpMomentCInvariant.cpp.

◆ Px()

double vpMomentCInvariant::Px ( )
inline

Shorcut for getting the value of $P_x$.

Definition at line 241 of file vpMomentCInvariant.h.

◆ Py()

double vpMomentCInvariant::Py ( )
inline

Shorcut for getting the value of $P_y$.

Definition at line 245 of file vpMomentCInvariant.h.

◆ Sx()

double vpMomentCInvariant::Sx ( ) const
inline

Shorcut for getting the value of $S_x$.

Definition at line 250 of file vpMomentCInvariant.h.

◆ Sy()

double vpMomentCInvariant::Sy ( ) const
inline

Shorcut for getting the value of $S_y$.

Definition at line 254 of file vpMomentCInvariant.h.

◆ 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 vpMomentCInvariant v 
)
friend

Outputs the moment's values to a stream.

Definition at line 287 of file vpMomentCInvariant.cpp.

Member Data Documentation

◆ values

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

Definition at line 117 of file vpMoment.h.

vpMomentCInvariant::get
double get(unsigned int i) const
Definition: vpMomentCInvariant.h:198
vpMoment::linkTo
void linkTo(vpMomentDatabase &moments)
Definition: vpMoment.cpp:97
vpMomentCInvariant
Definition: vpMomentCInvariant.h:126
vpMomentCentered
This class defines the double-indexed centered moment descriptor .
Definition: vpMomentCentered.h:78
vpPoint::set_x
void set_x(const double x)
Set the point x coordinate in the image plane.
Definition: vpPoint.cpp:469
vpMomentGravityCenter::compute
void compute()
Definition: vpMomentGravityCenter.cpp:44
vpMomentCommon
This class initializes and allows access to commonly used moments.
Definition: vpMomentCommon.h:103
vpMomentDatabase::updateAll
virtual void updateAll(vpMomentObject &object)
Definition: vpMomentDatabase.cpp:81
vpMomentDatabase
This class allows to register all vpMoments so they can access each other according to their dependen...
Definition: vpMomentDatabase.h:130
vpMomentObject::DISCRETE
Definition: vpMomentObject.h:230
vpMoment::update
void update(vpMomentObject &object)
Definition: vpMoment.cpp:114
vpMomentCommon::getMu3
static std::vector< double > getMu3(vpMomentObject &object)
Definition: vpMomentCommon.cpp:198
vpMomentObject
Class for generic objects.
Definition: vpMomentObject.h:218
vpPoint::set_y
void set_y(const double y)
Set the point y coordinate in the image plane.
Definition: vpPoint.cpp:471
vpMomentDatabase::get
const vpMoment & get(const char *type, bool &found) const
Definition: vpMomentDatabase.cpp:63
vpMomentCentered::compute
void compute()
Definition: vpMomentCentered.cpp:64
vpPoint
Class that defines what is a point.
Definition: vpPoint.h:57
vpMomentCommon::getSurface
static double getSurface(vpMomentObject &object)
Definition: vpMomentCommon.cpp:148
vpMomentGravityCenter
Class describing 2D gravity center moment.
Definition: vpMomentGravityCenter.h:112
vpMomentCommon::getAlpha
static double getAlpha(vpMomentObject &object)
Definition: vpMomentCommon.cpp:175