MomentCInvariant¶
- class MomentCInvariant(self, flg_sxsynormalization: bool = false)¶
Bases:
Moment
This class defines several 2D (translation+rotation+scale) invariants for both symmetric and non-symmetric objects. These moment-based invariants are described in the following papers [5] , [42] .
The descriptions for the invariants \(C_1\) to \(C_{10}\) can be found in [5] and for invariants \(P_x\) , \(P_y\) , \(S_x\) , \(S_y\) in [42] .
These invariants are classicaly used in visual servoing to control the out-of-plane rotations. The C-type or P-type invariants are used for non-symmetric objects whereas the S-type invariants are used for symmetric objects.
For most cases of non-symmetric objects, ( \(C_4\) , \(C_6\) ) or ( \(P_x\) , \(P_y\) ) couples are widely used to control x and y rotations. For symmetric objects \(S_x\) and \(S_y\) are the only choice.
There are 14 translation+rotation+scale invariants (10 C-type, 2 P-type and 2 S-type) that can be accessed from by vpMomentCInvariant::get or any of the get shortcuts.
The example below shows how to retrieve the \(C_2\) invariant:
#include <iostream> #include <visp3/core/vpMomentCInvariant.h> #include <visp3/core/vpMomentCommon.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(6); 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(3); // coordinates in meters in the image plane (vertex 2) vec_p.push_back(p); p.set_x(0); p.set_y(1.2); // coordinates in meters in the image plane (vertex 1) vec_p.push_back(p); p.set_x(-7); p.set_y(-4); // coordinates in meters in the image plane (vertex 2) vec_p.push_back(p); vpMomentObject obj(5); // Create an image moment object with 5 as maximum order obj.setType(vpMomentObject::DISCRETE); // Discrete mode for object obj.fromVector(vec_p); //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 const vpMomentCInvariant& C = static_cast<const vpMomentCInvariant&>(db.get("vpMomentCInvariant",success)); if(success) std::cout << C.get(1) << std:: endl; // print C2 invariant else std::cout << "vpMomentCInvariant not found." << std::endl; return 0; }
vpMomentCInvariant depends on vpMomentCentered (see vpMomentDatabase and vpMomentCommon ).
Methods
Shorcut for getting the value of \(C_1\) .
Shorcut for getting the value of \(C_{10}\) .
Shorcut for getting the value of \(C_2\) .
Shorcut for getting the value of \(C_3\) .
Shorcut for getting the value of \(C_4\) .
Shorcut for getting the value of \(C_5\) .
Shorcut for getting the value of \(C_6\) .
Shorcut for getting the value of \(C_7\) .
Shorcut for getting the value of \(C_8\) .
Shorcut for getting the value of \(C_9\) .
Shorcut for getting the value of \(P_x\) .
Shorcut for getting the value of \(P_y\) .
Shorcut for getting the value of \(S_x\) .
Shorcut for getting the value of \(S_y\) .
Computes translation-plane-rotation-scale invariants.
Overloaded function.
Access to partial invariant c (see [2]).
Getter for c (calculated from normalized 2nd and 3ord order moments)
Access to partial invariants.
Access to partial invariant I (see [2]).
Getters for I (calculated from normalized 2nd and 3ord order moments)
Access to partial invariant K (see [2]).
To get all the invariant values as a whole.
Access to partial invariant S (see [2]).
Getter for s (calculated from normalized 2nd and 3ord order moments)
To know if Sx and Sy were calculated from normalized moments or not
Moment name.
Print partial invariant.
Print the moment invariants used to obtain the actual visual features
Inherited Methods
Prints values of all dependent moments required to calculate a specific vpMoment .
Links the moment to a database of moment primitives.
Updates the moment with the current object.
Operators
__doc__
__module__
__repr__
Attributes
__annotations__
- compute(self) None ¶
Computes translation-plane-rotation-scale invariants. Depends on vpMomentCentered . All possible invariants are computed here. The selection of the invariant is done afterwards.
- get(*args, **kwargs)¶
Overloaded function.
get(self: visp._visp.core.MomentCInvariant, i: int) -> float
Gets the desired invariant.
- Parameters:
- i
given index. For invariants from C1 to C10 the corresponding index is from 0 to 9. For \(S_x\) , \(S_y\) the indexes are 10,11 and for \(P_x\) , \(P_y\) they are 12,13.
get(self: visp._visp.core.Moment) -> list[float]
- Returns:
vector of values
- getI(self, index: int) float ¶
Access to partial invariants. The index convention is the same as in [1].
- getObject(self) visp._visp.core.MomentObject ¶
- isSxSyfromNormalizedMoments(self) bool ¶
To know if Sx and Sy were calculated from normalized moments or not
- 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(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
- printI(self, index: int) None ¶
Print partial invariant.
Prints the temporary invariants. Used for debug purposes only
- printInvariants(self: visp._visp.core.MomentCInvariant, os: std::ostream) None ¶
Print the moment invariants used to obtain the actual visual features
Print out all invariants that were computed There are 15 of them, as in [Point-based and region based.ITRO05] [42]
- update(self, object: visp._visp.core.MomentObject) None ¶
Updates the moment with the current object. This does not compute any values.