Visual Servoing Platform  version 3.2.0 under development (2018-10-16)
vpMomentAlpha Class Reference

#include <visp3/core/vpMomentAlpha.h>

+ Inheritance diagram for vpMomentAlpha:

Public Member Functions

 vpMomentAlpha ()
 
 vpMomentAlpha (const std::vector< double > &ref, double alphaRef)
 
virtual ~vpMomentAlpha ()
 
void compute ()
 
double get () const
 
const char * name () const
 
bool is_ref () const
 
bool is_symmetric () 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

vpMomentDatabasegetMoments () const
 

Protected Attributes

std::vector< double > values
 

Friends

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

Detailed Description

This class defines the orientation of the object inside the plane parallel to the object.

In general the value of the moment is computed in $ [-\pi/2 .. \pi/2] $ interval by the formula $ \alpha = \frac{1}{2} arctan(\frac{2\mu_{11}}{\mu_{20}-\mu_{02}}) $.

To obtain a $ [-\pi .. \pi] $ precision for non symetric object, you have to specify a reference information. This reference information is an alpha computed using the previous formula in $ [-\pi/2 .. \pi/2] $. Obtaining this precision comes from third-order centered moments and this reference information.

Therefore there are two modes for vpMomentAlpha and one constructor per mode:

  • Reference mode (using the empty constructor vpMomentAlpha()): The vpMomentAlpha doesn't need any additionnal information, it will compute its values from available moments in $ [-\pi/2 .. \pi/2] $.
  • Relative mode (using non-empty constructor vpMomentAlpha(std::vector<double>&, double)): The vpMomentAlpha is computed in $ [-\pi .. \pi] $ from the available moments and the reference information. By knowing the reference, it may distinguish in-plane rotations of $ \alpha $ from rotations of $ \alpha + \pi $.

The following code demonstrates a calculation of a reference alpha and then uses this alpha to estimate the orientation of the same object after performing a 180 degrees rotation. Therefore the first and second alpha should have opposite values.

#include <visp3/core/vpMomentObject.h>
#include <visp3/core/vpPoint.h>
#include <visp3/core/vpMomentGravityCenter.h>
#include <visp3/core/vpMomentDatabase.h>
#include <visp3/core/vpMomentCentered.h>
#include <visp3/core/vpMomentAlpha.h>
#include <iostream>
#include <vector>
#include <algorithm>
//generic function for printing
void print (double i) { std::cout << i << "\t";}
int main()
{
// vector that contains the vertices of the contour polygon
std::vector<vpPoint> vec_p;
// coordinates in meters in the image plane (vertex 1)
p.set_x(1); p.set_y(1);
vec_p.push_back(p);
// coordinates in meters in the image plane (vertex 2)
p.set_x(2); p.set_y(2);
vec_p.push_back(p);
// coordinates in meters in the image plane (vertex 3)
p.set_x(-3); p.set_y(0);
vec_p.push_back(p);
// coordinates in meters in the image plane (vertex 4)
p.set_x(-3); p.set_y(-1);
vec_p.push_back(p);
vpMomentObject objRef(3); // Reference object. Must be of order 3
// because we will need the 3rd order
// centered moments
// object is the inner part of a polygon
objRef.fromVector(vec_p); // Init the dense object with the polygon
vpMomentDatabase dbRef; //reference database
vpMomentGravityCenter gRef; // declaration of gravity center
vpMomentCentered mcRef; // centered moments
vpMomentAlpha alphaRef; //declare alpha as reference
gRef.linkTo(dbRef); //add gravity center to database
mcRef.linkTo(dbRef); //add centered moments
alphaRef.linkTo(dbRef); //add alpha depending on centered moments
dbRef.updateAll(objRef); // All of the moments must be updated, not just alpha
gRef.compute(); // compute the moment
mcRef.compute(); //compute centered moments AFTER gravity center
alphaRef.compute(); //compute alpha AFTER centered moments.
//the order of values in the vector must be as follows:
//mu30 mu21 mu12 mu03
std::vector<double> mu3ref(4);
mu3ref[0] = mcRef.get(3,0);
mu3ref[1] = mcRef.get(2,1);
mu3ref[2] = mcRef.get(1,2);
mu3ref[3] = mcRef.get(0,3);
std::cout << "--- Reference object ---" << std::endl;
std::cout << "alphaRef=" << alphaRef << std::endl << "mu3="; // print reference alpha
std::for_each (mu3ref.begin(), mu3ref.end(),print);
std::cout << std::endl;
vec_p.clear();
p.set_x(-3); p.set_y(1); // coordinates in meters in the image plane (vertex 4)
vec_p.push_back(p);
p.set_x(-3); p.set_y(0); // coordinates in meters in the image plane (vertex 3)
vec_p.push_back(p);
p.set_x(2); p.set_y(-2); // coordinates in meters in the image plane (vertex 2)
vec_p.push_back(p);
p.set_x(1); p.set_y(-1); // coordinates in meters in the image plane (vertex 1)
vec_p.push_back(p);
vpMomentObject obj(3); // second object. Order 3 is also required
// because of the Alpha will compare
// third-order centered moments to given reference.
obj.setType(vpMomentObject::DENSE_POLYGON); // object is the inner part of a polygon
obj.fromVector(vec_p); // Init the dense object with the polygon
vpMomentDatabase db; // database
vpMomentGravityCenter g; // declaration of gravity center
vpMomentCentered mc; // mc containts centered moments
vpMomentAlpha alpha(mu3ref,alphaRef.get()); //declare alpha as relative to a reference
g.linkTo(db); //add gravity center to database
mc.linkTo(db); //add centered moments
alpha.linkTo(db); //add alpha depending on centered moments
db.updateAll(obj); // All of the moments must be updated
g.compute(); // compute the moment
mc.compute(); //compute centered moments AFTER gravity center
alpha.compute(); //compute alpha AFTER centered moments.
std::cout << "--- current object ---" << std::endl;
std::cout << "alpha=" << alpha.get() << std::endl;
return 0;
}

This program outputs:

--- Reference object ---
alphaRef=0.441601
mu3=1.80552 0.921882 0.385828 0.122449
--- current object ---
alpha=-0.441601

Shortcuts for quickly getting those references exist in vpMomentCommon.

This moment depends on vpMomentCentered.

Definition at line 208 of file vpMomentAlpha.h.

Constructor & Destructor Documentation

vpMomentAlpha::vpMomentAlpha ( )

Empty constructor. Initializes alpha moment as a reference alpha with a value in $[-\pi/2..\pi/2]$. A default-constructed alpha moment may be used as a reference information for other alphas. A reference alpha is a class harbouring an alpha value computed for a $[-\pi/2..\pi/2]$ portion of the circle.

Definition at line 51 of file vpMomentAlpha.cpp.

References vpMoment::values.

vpMomentAlpha::vpMomentAlpha ( const std::vector< double > &  ref_,
double  alpha_ref 
)

Common constructor. Initializes alpha moment as a non-reference alpha with a value computed in $[-\pi..\pi]$.

Parameters
ref_: vector of 3rd order centered moments corresponding to the reference alpha in the following order: $\mu_{30},\mu_{21},\mu_{12},\mu_{03}$.
alpha_ref: value of the reference alpha.

Definition at line 60 of file vpMomentAlpha.cpp.

References vpMoment::values.

virtual vpMomentAlpha::~vpMomentAlpha ( )
inlinevirtual

Definition at line 219 of file vpMomentAlpha.h.

References vpMoment::compute().

Member Function Documentation

void vpMomentAlpha::compute ( )
virtual
double vpMomentAlpha::get ( ) const
inline

Retrieve the orientation of the object as a single double value.

Definition at line 225 of file vpMomentAlpha.h.

Referenced by vpMomentCommon::getAlpha().

bool vpMomentAlpha::is_ref ( ) const
inline

Definition at line 231 of file vpMomentAlpha.h.

bool vpMomentAlpha::is_symmetric ( ) const
inline

Definition at line 239 of file vpMomentAlpha.h.

References vpMoment::operator<<, and vpMoment::printDependencies().

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.

Definition at line 98 of file vpMoment.cpp.

References vpException::memoryAllocationError, and vpMoment::name().

Referenced by vpMomentCommon::getAlpha(), vpMomentCommon::getMu3(), vpMomentCommon::getSurface(), and vpMomentCommon::vpMomentCommon().

const char* vpMomentAlpha::name ( ) const
inlinevirtual

Moment name.

Implements vpMoment.

Definition at line 229 of file vpMomentAlpha.h.

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

Prints the dependencies of alpha, namely centered moments mu11, mu20 ad mu02

Reimplemented from vpMoment.

Definition at line 160 of file vpMomentAlpha.cpp.

References vpMomentCentered::get(), vpMomentDatabase::get(), vpMoment::getMoments(), and vpException::notInitialized.

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 115 of file vpMoment.cpp.

Friends And Related Function Documentation

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

Prints the value of the major-axis orientation in degrees and rad

Definition at line 150 of file vpMomentAlpha.cpp.

Member Data Documentation