MomentGravityCenter¶
- class MomentGravityCenter(self)¶
Bases:
Moment
Class describing 2D gravity center moment.
This moment can be computed from scratch (no need to compute any different moments before computing this). It gives access to both coordinates of the gravity center \(x_g\) and \(y_g\) .
These coordinates are defined as follows: \(x_g = \frac{m_{01}}{m_{00}}\) , \(y_g = \frac{m_{10}}{m_{00}}\)
#include <iostream> #include <visp3/core/vpMomentGravityCenter.h> #include <visp3/core/vpMomentObject.h> #include <visp3/core/vpPoint.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { // Define the contour of an object by a 5 clockwise vertices on a plane vpPoint p; 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 obj(1); // Create an image moment object with 1 as // maximum order (because only m00,m01,m10 // are needed to compute the gravity center primitive. obj.setType(vpMomentObject::DENSE_POLYGON); // The object is defined by a contour polygon obj.fromVector(vec_p); // Init the dense object with the polygon vpMomentGravityCenter g; // declaration of gravity center g.update(obj); // specify the object g.compute(); // compute the moment std::cout << "Xg=" << g.getXg() << std::endl; // access to Xg std::cout << "Yg=" << g.getYg() << std::endl; // access to Yg std::cout << g << std:: endl; // print gravity center return 0; }
This example produces the following results:
Xg=0.0166667 Yg=-0.00833333 Xg=0.0166667, Yg=-0.00833333
Default constructor.
Methods
Default constructor.
Computes the two gravity center coordinates commonly called \(x_g\) and \(y_g\) .
Overloaded function.
- return:
The first gravity center coordinate.
- return:
The second gravity center coordinate.
The class's string name.
Overloaded function.
Inherited Methods
Links the moment to a database of moment primitives.
Updates the moment with the current object.
Operators
__doc__
Default constructor.
__module__
__repr__
Attributes
__annotations__
- __init__(self)¶
Default constructor.
- compute(self) None ¶
Computes the two gravity center coordinates commonly called \(x_g\) and \(y_g\) .
- get(*args, **kwargs)¶
Overloaded function.
get(self: visp._visp.core.MomentGravityCenter) -> list[float]
- Returns:
Coordinates in the following moment: \((x_g,y_g)\) .
get(self: visp._visp.core.Moment) -> list[float]
- Returns:
vector of values
- getObject(self) visp._visp.core.MomentObject ¶
- linkTo(self, moments: visp._visp.core.MomentDatabase) None ¶
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.
Warning
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> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpPoint p; 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) vec_p.push_back(p); vpMomentObject obj(2); obj.setType(vpMomentObject::DISCRETE); // Discrete mode. obj.fromVector(vec_p); // Init the dense object with the polygon vpMomentDatabase db; vpMomentGravityCenter G; // declaration of gravity center vpMomentCentered mc; // mc contains 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; }
- printDependencies(*args, **kwargs)¶
Overloaded function.
printDependencies(self: visp._visp.core.MomentGravityCenter, os: std::ostream) -> None
Prints its dependencies Basic moments m10, m01 and m00 from vpMomentObject
printDependencies(self: visp._visp.core.Moment, os: std::ostream) -> None
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
- update(self, object: visp._visp.core.MomentObject) None ¶
Updates the moment with the current object. This does not compute any values.