MomentDatabase¶
- class MomentDatabase(self)¶
Bases:
pybind11_object
This class allows to register all vpMoments so they can access each other according to their dependencies.
Sometimes, a moment needs to have access to other moment’s values to be computed. For example vpMomentCentered needs additional information about the gravity center vpMomentGravityCenter in order to compute the moment’s value from a vpMomentObject . This gravity center should be stored in a vpMomentDatabase where it can be accessed.
All moments in a database can access each other freely at any time. They can also verify if a moment is present in the database or not. Here is a example of a dependency between two moments using a vpMomentDatabase :
#include <iostream> #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; // 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); vpMomentObject obj(1); // Create an image moment object with 1 as // maximum order (sufficient for gravity center) obj.setType(vpMomentObject::DISCRETE); // The object is defined by // two discrete points 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 db.updateAll(obj); // All of the moments must be updated, not just mc //There is no global compute method since the order of compute calls //depends on the implementation g.compute(); // compute the moment mc.compute(); //compute centered moments AFTER gravity center std::cout << "Gravity center: " << g << std:: endl; // print gravity center moment std::cout << "Centered moments: " << mc << std:: endl; // print centered moment return 0; }
The following code outputs:
Gravity center: Xg=1.5, Yg=1.5 Centered moments: 2 0 0 x
A moment is identified in the database by it’s vpMoment::name method. Consequently, a database can contain at most one moment of each type. Often it is useful to update all moments with the same object. Shortcuts ( vpMomentDatabase::updateAll ) are provided for that matter.
Methods
- param moment_name:
Name of the moment's class.
Get the first element in the database.
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.
Inherited Methods
Operators
__annotations__
__doc__
__module__
__repr__
Attributes
__annotations__
- __init__(self)¶
- get(self, moment_name: str) tuple[visp._visp.core.Moment, bool] ¶
- 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(self, 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: visp._visp.core.MomentObject¶
Moment object for which all the moments in the database should be updated.