Visual Servoing Platform  version 3.3.0
vpFeatureMomentCommon Class Reference

#include <vpFeatureMomentCommon.h>

+ Inheritance diagram for vpFeatureMomentCommon:

Public Member Functions

 vpFeatureMomentCommon (vpMomentDatabase &moments, double A=0.0, double B=0.0, double C=1.0)
 
void updateAll (double A, double B, double C)
 
vpFeatureMomentAlphagetFeatureAlpha ()
 
vpFeatureMomentAreaNormalizedgetFeatureAn ()
 
vpFeatureMomentBasicgetFeatureMomentBasic ()
 
vpFeatureMomentCenteredgetFeatureCentered ()
 
vpFeatureMomentCInvariantgetFeatureCInvariant ()
 
vpFeatureMomentGravityCenterNormalizedgetFeatureGravityNormalized ()
 
vpFeatureMomentAreagetFeatureArea ()
 
vpFeatureMomentGravityCentergetFeatureGravityCenter ()
 
vpFeatureMomentget (const char *type, bool &found)
 

Detailed Description

This class allows to access common vpFeatureMoments in a pre-filled database.

It is a vpMomentDatabase filled with the following moments:

There is no need to do the linkTo operations manually nor is it necessary to care about the order of feature computation.

This class has an vpMomentCommon::updateAll method capable of updating the plane parameters AND computing interaction matrices inside the features.

The moment features computed by this class are classical moments features used in moment-based visual servoing. For more information see [Tahri05z].

To initialize this feature set, the user needs to supply a vpMomentDatabase containing at least the contents of vpMomentCommon.

The features can be retrieved like from a normal vpFeatureMomentDatabase. However, some shortcuts to retrieve the features are provided.

Attention
Make sure your object is at least of order 6 when using this pre-filled database.

The following code demonstrates the construction of a 6x6 interaction matrix as described in [1].

#include <visp3/core/vpMomentObject.h>
#include <visp3/core/vpMomentCommon.h>
#include <visp3/core/vpPoint.h>
#include <visp3/visual_features/vpFeatureMoment.h>
#include <visp3/visual_features/vpFeatureMomentCommon.h>
#include <visp3/vs/vpServo.h>
#include <iostream>
#include <vector>
int main()
{
// Define source polygon
std::vector<vpPoint> vec_p; // vector that contains the vertices of the contour polygon
p.set_x(-0.2); p.set_y(0.1); // coordinates in meters in the image plane (vertex 1)
vec_p.push_back(p);
p.set_x(+0.3); p.set_y(0.1); // coordinates in meters in the image plane (vertex 2)
vec_p.push_back(p);
p.set_x(+0.2); p.set_y(-0.1); // coordinates in meters in the image plane (vertex 3)
vec_p.push_back(p);
p.set_x(-0.2); p.set_y(-0.15); // coordinates in meters in the image plane (vertex 4)
vec_p.push_back(p);
p.set_x(-0.2); p.set_y(0.1); // close the contour (vertex 5 = vertex 1)
vec_p.push_back(p);
vpMomentObject src(6); // Create a source moment object with 6 as maximum order
src.setType(vpMomentObject::DENSE_POLYGON); // The object is defined by a countour polygon
src.fromVector(vec_p); // Init the dense object with the source polygon
vec_p.clear();
//Define destination polygon. This is the source polygon translated
//of 0.1 on x-axis
p.set_x(-0.1); p.set_y(0.1); // coordinates in meters in the image plane (vertex 1)
vec_p.push_back(p);
p.set_x(+0.4); p.set_y(0.1); // coordinates in meters in the image plane (vertex 2)
vec_p.push_back(p);
p.set_x(+0.3); p.set_y(-0.1); // coordinates in meters in the image plane (vertex 3)
vec_p.push_back(p);
p.set_x(-0.1); p.set_y(-0.15); // coordinates in meters in the image plane (vertex 4)
vec_p.push_back(p);
p.set_x(-0.1); p.set_y(0.1); // close the contour (vertex 5 = vertex 1)
vec_p.push_back(p);
vpMomentObject dst(6); // Create a destination moment object with 6 as maximum order
dst.setType(vpMomentObject::DENSE_POLYGON); // The object is defined by a countour polygon
dst.fromVector(vec_p); // Init the dense object with the destination
// polygon
//init classic moment primitives (for source)
//Init classic features
vpFeatureMomentCommon fmdb_src(mdb_src);
//Init classic features
vpFeatureMomentCommon fmdb_dst(mdb_dst);
//update+compute moment primitives from object (for source)
mdb_src.updateAll(src);
//update+compute features (+interaction matrices) from plane
fmdb_src.updateAll(0.,0.,1.);
//update+compute moment primitives from object (for destination)
mdb_dst.updateAll(dst);
//update+compute features (+interaction matrices) from plane
fmdb_dst.updateAll(0.,0.,1.);
//define visual servoing task
vpServo task;
//Add all classic features to the task
//In this example, source and destination features are translated by 0.1
//will produce a movement of 0.1 on x-axis.
task.addFeature(fmdb_src.getFeatureGravityNormalized(),fmdb_dst.getFeatureGravityNormalized());
task.addFeature(fmdb_src.getFeatureAn(),fmdb_dst.getFeatureAn());
//the object is NOT symmetric
//select C4 and C6
task.addFeature(fmdb_src.getFeatureCInvariant(),fmdb_dst.getFeatureCInvariant(),(1 << 3) | (1 << 5));
task.addFeature(fmdb_src.getFeatureAlpha(),fmdb_dst.getFeatureAlpha());
task.setLambda(1) ;
task.print();
task.kill();
return 0;
}

This code produces the following output:

Visual servoing task:
Type of control law
Eye-in-hand configuration
Control in the camera frame
List of visual features : s
0.0166667,-0.00833333,
1,
-0.312148,0.0249916,
-1.43449,
List of desired visual features : s*
0.116667,-0.00833333,
1,
-0.312148,0.0249916,
-1.43449,
Interaction Matrix Ls
-1 0 -6.938893904e-18 0.007291666667 -1.06875 -0.008333333333
0 -1 3.469446952e-18 1.0171875 -0.007291666667 -0.01666666667
0 0 -1 0.0125 0.025 0
0 0 -4.585529113e-15 -0.2983860943 0.5832596643 -4.376751552e-16
0 0 -3.58244462e-15 0.08633028234 -0.2484618767 3.63421192e-16
4.353086256e-17 -1.339411156e-16 -0 -0.03019436997 -0.0168230563 -1
Error vector (s-s*)
-0.1 0 0 1.831867991e-15 -1.072059108e-15 0
Gain : Zero= 1 Inf= 1 Deriv= 0
Examples
manServoMomentsSimple.cpp, servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 225 of file vpFeatureMomentCommon.h.

Constructor & Destructor Documentation

◆ vpFeatureMomentCommon()

vpFeatureMomentCommon::vpFeatureMomentCommon ( vpMomentDatabase moments,
double  A = 0.0,
double  B = 0.0,
double  C = 1.0 
)

Constructor which initializes and links all common features in the database

Parameters
moments: database for moment primitives
A: first plane coefficient for a plane equation of the following type Ax+By+C=1/Z
B: second plane coefficient for a plane equation of the following type Ax+By+C=1/Z
C: third plane coefficient for a plane equation of the following type Ax+By+C=1/Z

Definition at line 50 of file vpFeatureMomentCommon.cpp.

Member Function Documentation

◆ get()

vpFeatureMoment & vpFeatureMomentDatabase::get ( const char *  type,
bool &  found 
)
inherited

Retrieves a moment feature from the database

Parameters
type: the name of the feature, the one specified when using add
found: true if the type string is found inside the database, false otherwise
Returns
the moment feature corresponding to the type string

Definition at line 63 of file vpFeatureMomentDatabase.cpp.

◆ getFeatureAlpha()

vpFeatureMomentAlpha& vpFeatureMomentCommon::getFeatureAlpha ( )
inline

Returns alpha.

Examples
servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 243 of file vpFeatureMomentCommon.h.

◆ getFeatureAn()

vpFeatureMomentAreaNormalized& vpFeatureMomentCommon::getFeatureAn ( )
inline

Returns normalized surface.

Examples
servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 248 of file vpFeatureMomentCommon.h.

◆ getFeatureArea()

vpFeatureMomentArea& vpFeatureMomentCommon::getFeatureArea ( )
inline

Returns the area

Definition at line 269 of file vpFeatureMomentCommon.h.

◆ getFeatureCentered()

vpFeatureMomentCentered& vpFeatureMomentCommon::getFeatureCentered ( )
inline

Returns centered moments.

Definition at line 256 of file vpFeatureMomentCommon.h.

◆ getFeatureCInvariant()

vpFeatureMomentCInvariant& vpFeatureMomentCommon::getFeatureCInvariant ( )
inline

Returns non-symmetric invariants.

Examples
servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 261 of file vpFeatureMomentCommon.h.

◆ getFeatureGravityCenter()

vpFeatureMomentGravityCenter& vpFeatureMomentCommon::getFeatureGravityCenter ( )
inline

Returns gravity center

Definition at line 273 of file vpFeatureMomentCommon.h.

◆ getFeatureGravityNormalized()

vpFeatureMomentGravityCenterNormalized& vpFeatureMomentCommon::getFeatureGravityNormalized ( )
inline

Returns normalized gravity center.

Examples
servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 265 of file vpFeatureMomentCommon.h.

◆ getFeatureMomentBasic()

vpFeatureMomentBasic& vpFeatureMomentCommon::getFeatureMomentBasic ( )
inline

Returns basic moment.

Definition at line 252 of file vpFeatureMomentCommon.h.

◆ updateAll()

void vpFeatureMomentCommon::updateAll ( double  A,
double  B,
double  C 
)
virtual

Update all moment features in the database with plane coefficients

Parameters
A: first plane coefficient for a plane equation of the following type Ax+By+C=1/Z
B: second plane coefficient for a plane equation of the following type Ax+By+C=1/Z
C: third plane coefficient for a plane equation of the following type Ax+By+C=1/Z

Reimplemented from vpFeatureMomentDatabase.

Examples
servoMomentImage.cpp, servoMomentPoints.cpp, and servoMomentPolygon.cpp.

Definition at line 73 of file vpFeatureMomentCommon.cpp.

vpFeatureMomentCommon
This class allows to access common vpFeatureMoments in a pre-filled database.
Definition: vpFeatureMomentCommon.h:225
vpServo::kill
void kill()
Definition: vpServo.cpp:191
vpMomentObject::setType
void setType(vpObjectType input_type)
Definition: vpMomentObject.h:293
vpServo::CURRENT
Definition: vpServo.h:185
vpMomentCommon
This class initializes and allows access to commonly used moments.
Definition: vpMomentCommon.h:103
vpServo::setLambda
void setLambda(double c)
Definition: vpServo.h:405
vpServo::EYEINHAND_CAMERA
Definition: vpServo.h:158
vpMomentObject::DENSE_POLYGON
Definition: vpMomentObject.h:227
vpColVector
Implementation of column vector and the associated operations.
Definition: vpColVector.h:129
vpServo::setServo
void setServo(const vpServoType &servo_type)
Definition: vpServo.cpp:222
vpServo::print
void print(const vpServo::vpServoPrintType display_level=ALL, std::ostream &os=std::cout)
Definition: vpServo.cpp:312
vpMomentObject::fromVector
void fromVector(std::vector< vpPoint > &points)
Definition: vpMomentObject.cpp:229
vpServo::e
vpColVector e
Task .
Definition: vpServo.h:566
vpPoint::set_y
void set_y(double y)
Set the point y coordinate in the image plane.
Definition: vpPoint.cpp:473
vpMomentCommon::getMu3
static std::vector< double > getMu3(vpMomentObject &object)
Definition: vpMomentCommon.cpp:198
vpServo::addFeature
void addFeature(vpBasicFeature &s, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
Definition: vpServo.cpp:496
vpMomentObject
Class for generic objects.
Definition: vpMomentObject.h:218
vpServo::setInteractionMatrixType
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
Definition: vpServo.cpp:573
vpServo
Definition: vpServo.h:149
vpServo::computeControlLaw
vpColVector computeControlLaw()
Definition: vpServo.cpp:934
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
vpMomentCommon::getSurface
static double getSurface(vpMomentObject &object)
Definition: vpMomentCommon.cpp:148
vpMomentCommon::getAlpha
static double getAlpha(vpMomentObject &object)
Definition: vpMomentCommon.cpp:175