ViSP  2.9.0
vpMomentAlpha Class Reference

#include <vpMomentAlpha.h>

+ Inheritance diagram for vpMomentAlpha:

Public Member Functions

 vpMomentAlpha ()
 
 vpMomentAlpha (std::vector< double > &ref, double alphaRef)
 
void compute ()
 
double get () const
 
const char * name () const
 
bool is_ref () const
 
bool is_symmetric () const
 
const vpMomentObjectgetObject () const
 
void linkTo (vpMomentDatabase &moments)
 
void update (vpMomentObject &object)
 

Protected Member Functions

vpMomentDatabasegetMoments ()
 

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.

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

To obtain the $ [-\pi .. \pi] $ precision, you have to specify reference information. This reference information describes an object with 0 rad orientation or at least an orientation between $ -\pi/2 $ and $ \pi/2 $ rad. The nature of this information are third-order centered moments and a reference value of alpha. Reference centered moments are obtained with vpMomentCentered and reference alpha is obtained with vpMomentAlpha using the reference constructor.

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

  • Reference mode (using the empty constructor): The vpMomentAlpha doesn't need any additionnal information, it will compute its values from a reference object.
  • Relative mode (using non-empty constructor): The vpMomentAlpha is computed relative a reference alpha. 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 <visp/vpMomentObject.h>
#include <visp/vpPoint.h>
#include <visp/vpMomentGravityCenter.h>
#include <visp/vpMomentDatabase.h>
#include <visp/vpMomentCentered.h>
#include <visp/vpMomentAlpha.h>
#include <iostream>
#include <vector>
#include <algorithm>
//generic function for printing
void print (double i) { std::cout << i << "\t";}
int main()
{
std::vector<vpPoint> vec_p; // vector that contains the vertices of the contour polygon
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)
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(-3); p.set_y(-1); // coordinates in meters in the image plane (vertex 4)
vec_p.push_back(p);
vpMomentObject objRef(3); // Reference object. Must be of order 3
// because we will need the 3rd order
// centered moments
objRef.setType(vpMomentObject::DENSE_POLYGON); // 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 198 of file vpMomentAlpha.h.

Constructor & Destructor Documentation

vpMomentAlpha::vpMomentAlpha ( )

Empty constructor. Initializes alpha moment as a reference alpha. A default-constructed alpha moment may be used as a reference for other alphas. A reference alpha is class harbouring an alpha value computed for a $[-\pi/2..\pi/2]$ portion of the circle. Not setting a reference alpha will prevent you from doing more than 180deg rotation with moments.

Definition at line 52 of file vpMomentAlpha.cpp.

References vpMoment::values.

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

Common constructor. Initializes alpha moment as a non-reference alpha. A default-constructed alpha moment must be used as a reference for other this alpha. A reference alpha is class harbouring an alpha value computed for a $[0..\pi]$ portion of the circle. Not having a reference alpha will prevent you from doing more than 180deg rotation with moments.

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

Definition at line 63 of file vpMomentAlpha.cpp.

References vpMoment::values.

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 213 of file vpMomentAlpha.h.

Referenced by vpMomentCommon::getAlpha().

vpMomentDatabase& vpMoment::getMoments ( )
inlineprotectedinherited

Returns the linked moment database.

Returns
the moment database

Definition at line 119 of file vpMoment.h.

Referenced by vpMomentArea::compute(), vpMomentGravityCenterNormalized::compute(), vpMomentCentered::compute(), vpMomentAreaNormalized::compute(), vpMomentCInvariant::compute(), and compute().

bool vpMomentAlpha::is_ref ( ) const
inline

Definition at line 219 of file vpMomentAlpha.h.

bool vpMomentAlpha::is_symmetric ( ) const
inline

Definition at line 227 of file vpMomentAlpha.h.

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 <visp/vpMomentObject.h>
#include <visp/vpPoint.h>
#include <visp/vpMomentGravityCenter.h>
#include <visp/vpMomentDatabase.h>
#include <visp/vpMomentCentered.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.

Definition at line 103 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 217 of file vpMomentAlpha.h.

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 120 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 orientation.

Definition at line 152 of file vpMomentAlpha.cpp.

Member Data Documentation