MomentCommon¶
- class MomentCommon(self, dstSurface: float, ref: list[float], refAlpha: float, dstZ: float = 1.0, flg_sxsyfromnormalized: bool = false)¶
Bases:
MomentDatabase
This class initializes and allows access to commonly used moments.
It is a vpMomentDatabase filled with the following moments:
vpMomentBasic
vpMomentGravityCenter
vpMomentCentered
vpMomentGravityCenterNormalized
vpMomentAreaNormalized
vpMomentCInvariant
vpMomentAlpha
vpMomentArea
There is no need to do the linkTo operations manually nor is it necessary to care about the order of moment computation.
This class carries an vpMomentCommon::updateAll() method capable of updating AND computing moments from an object (see 4-step process in vpMoment ). The moments computed by this class are classical moments used in moment-based visual servoing. For more information see [40] .
To initialize this moment set the user needs to compute the following things:
the Mu3 value set: set of third-order centered moments computed for a reference object. ( \(\mu_{ij}$ with $i+j = 3\) ). These values allow the system to save the reference angular position and to perform planar rotations of more than 180 degrees if needed.
the destination depth.
the surface of the destination object in the end of the visual servoing process.
the reference alpha: angular position of the object used to obtain the Mu3 set.
Shortcuts for each of these prerequisites are provided by this class except depth (methods vpMomentCommon::getMu3() , vpMomentCommon::getSurface() , vpMomentCommon::getAlpha() ).
Warning
Make sure your object is at least of order 5 when using this pre-filled database.
Default constructor. Initializes the common database with the following moments: basic, gravity,centered,centered+normalized,normalized gravity,normalized surface, scale-plane-rotation-translation invariant, alpha, symmetric invariant.
- Parameters:
- dstSurface: float¶
destination surface. You may use vpMomentCommon::getSurface() .
- ref: list[float]¶
reference 3rd order moments (see vpMomentAlpha ). You may use vpMomentCommon::getMu3() .
- refAlpha: float¶
reference alpha (see vpMomentAlpha ). You may use vpMomentCommon::getAlpha() .
- dstZ: float = 1.0¶
destination depth.
- flg_sxsyfromnormalized: bool = false¶
flag to enable calculation of sx,sy from normalized moments.
Methods
Default constructor.
Gets a reference alpha of an object.
Gets the reference 3rd order moments of an object.
Gets the surface of an object
Overloaded function.
Inherited Methods
- param moment_name:
Name of the moment's class.
Get the first element in the database.
Operators
__doc__
Default constructor.
__module__
Attributes
__annotations__
- __init__(self, dstSurface: float, ref: list[float], refAlpha: float, dstZ: float = 1.0, flg_sxsyfromnormalized: bool = false)¶
Default constructor. Initializes the common database with the following moments: basic, gravity,centered,centered+normalized,normalized gravity,normalized surface, scale-plane-rotation-translation invariant, alpha, symmetric invariant.
- Parameters:
- dstSurface: float¶
destination surface. You may use vpMomentCommon::getSurface() .
- ref: list[float]¶
reference 3rd order moments (see vpMomentAlpha ). You may use vpMomentCommon::getMu3() .
- refAlpha: float¶
reference alpha (see vpMomentAlpha ). You may use vpMomentCommon::getAlpha() .
- dstZ: float = 1.0¶
destination depth.
- flg_sxsyfromnormalized: bool = false¶
flag to enable calculation of sx,sy from normalized moments.
- get(self, moment_name: str) tuple[visp._visp.core.Moment, bool] ¶
- static getAlpha(object: visp._visp.core.MomentObject) float ¶
Gets a reference alpha of an object.
- Parameters:
- object: visp._visp.core.MomentObject¶
Moment object.
- static getMu3(object: visp._visp.core.MomentObject) list[float] ¶
Gets the reference 3rd order moments of an object.
- Parameters:
- object: visp._visp.core.MomentObject¶
Moment object.
- static getSurface(object: visp._visp.core.MomentObject) float ¶
Gets the surface of an object
- Parameters:
- object: visp._visp.core.MomentObject¶
moment object
- get_first(self) visp._visp.core.Moment ¶
Get the first element in the database. May be useful in case an unnamed object is present but is the only element in the database.
- Returns:
the first element in the database.
- updateAll(*args, **kwargs)¶
Overloaded function.
updateAll(self: visp._visp.core.MomentCommon, object: visp._visp.core.MomentObject) -> None
Updates all moments in the database with the object and computes all their values. This is possible because this particular database knows the link between the moments it contains. The order of computation is as follows: vpMomentGravityCenter , vpMomentCentered , vpMomentAlpha , vpMomentCInvariant ,vpMomentSInvariant, vpMomentAreaNormalized , vpMomentGravityCenterNormalized Example of using a preconfigured database to compute one of the C-invariants:
#include <iostream> #include <visp3/core/vpMomentCInvariant.h> #include <visp3/core/vpMomentCommon.h> #include <visp3/core/vpMomentObject.h> #include <visp3/core/vpPoint.h> int main() { // Define two discrete points vpPoint p; std::vector<vpPoint> vec_p; // std::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 obj(5); // Object initialized up to order 5 to handle // all computations required by vpMomentCInvariant obj.setType(vpMomentObject::DENSE_POLYGON); // object is the inner part of a polygon obj.fromstd::vector(vec_p); // Init the discrete object with two points //initialisation with default values vpMomentCommon db(vpMomentCommon::getSurface(obj),vpMomentCommon::getMu3(obj),vpMomentCommon::getAlpha(obj),1.); bool success; db.updateAll(obj); // Update AND compute all moments //get C-invariant vpMomentCInvariant& C = static_cast<vpMomentCInvariant&>(db.get("vpMomentCInvariant",success)); if(success) { std::cout << C.get(0) << std:: std::endl; } else std::cout << "vpMomentCInvariant not found." << std::endl; return 0; }
- Parameters:
- object
Moment object.
updateAll(self: visp._visp.core.MomentDatabase, object: visp._visp.core.MomentObject) -> None
Updates the moment object for all moments in the databaseSometimes, it might be useful to update the whole database when computing only one moment when this moment depends on other moments. The example provided in the header of this class gives an example that shows how to compute gravity center moment and the centered moment using a mass update.
- Parameters:
- object
Moment object for which all the moments in the database should be updated.