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] , [40] .

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 [40] .

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>

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 ).

Default constructor. (option to use a different calculation mode for sx and sy)

Methods

C1

Shorcut for getting the value of \(C_1\) .

C10

Shorcut for getting the value of \(C_{10}\) .

C2

Shorcut for getting the value of \(C_2\) .

C3

Shorcut for getting the value of \(C_3\) .

C4

Shorcut for getting the value of \(C_4\) .

C5

Shorcut for getting the value of \(C_5\) .

C6

Shorcut for getting the value of \(C_6\) .

C7

Shorcut for getting the value of \(C_7\) .

C8

Shorcut for getting the value of \(C_8\) .

C9

Shorcut for getting the value of \(C_9\) .

Px

Shorcut for getting the value of \(P_x\) .

Py

Shorcut for getting the value of \(P_y\) .

Sx

Shorcut for getting the value of \(S_x\) .

Sy

Shorcut for getting the value of \(S_y\) .

__init__

Default constructor.

compute

Computes translation-plane-rotation-scale invariants.

get

Overloaded function.

getC

Access to partial invariant c (see [2]).

getCN

Getter for c (calculated from normalized 2nd and 3ord order moments)

getI

Access to partial invariants.

getII

Access to partial invariant I (see [2]).

getIn1

Getters for I (calculated from normalized 2nd and 3ord order moments)

getK

Access to partial invariant K (see [2]).

getMomentVector

To get all the invariant values as a whole.

getS

Access to partial invariant S (see [2]).

getSN

Getter for s (calculated from normalized 2nd and 3ord order moments)

isSxSyfromNormalizedMoments

To know if Sx and Sy were calculated from normalized moments or not

name

Moment name.

printI

Print partial invariant.

printInvariants

Print the moment invariants used to obtain the actual visual features

Inherited Methods

linkTo

Links the moment to a database of moment primitives.

getObject

printDependencies

Prints values of all dependent moments required to calculate a specific vpMoment .

update

Updates the moment with the current object.

Operators

__doc__

__init__

Default constructor.

__module__

__repr__

Attributes

__annotations__

C1(self) float

Shorcut for getting the value of \(C_1\) .

C10(self) float

Shorcut for getting the value of \(C_{10}\) .

C2(self) float

Shorcut for getting the value of \(C_2\) .

C3(self) float

Shorcut for getting the value of \(C_3\) .

C4(self) float

Shorcut for getting the value of \(C_4\) .

C5(self) float

Shorcut for getting the value of \(C_5\) .

C6(self) float

Shorcut for getting the value of \(C_6\) .

C7(self) float

Shorcut for getting the value of \(C_7\) .

C8(self) float

Shorcut for getting the value of \(C_8\) .

C9(self) float

Shorcut for getting the value of \(C_9\) .

Px(self) float

Shorcut for getting the value of \(P_x\) .

Py(self) float

Shorcut for getting the value of \(P_y\) .

Sx(self) float

Shorcut for getting the value of \(S_x\) .

Sy(self) float

Shorcut for getting the value of \(S_y\) .

__init__(self, flg_sxsynormalization: bool = false)

Default constructor. (option to use a different calculation mode for sx and sy)

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.

  1. 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.

  1. get(self: visp._visp.core.Moment) -> list[float]

Returns:

vector of values

getC(self, i: int) float

Access to partial invariant c (see [2]).

getCN(self, i: int) float

Getter for c (calculated from normalized 2nd and 3ord order moments)

getI(self, index: int) float

Access to partial invariants. The index convention is the same as in [1].

getII(self, i: int) float

Access to partial invariant I (see [2]).

getIn1(self) float

Getters for I (calculated from normalized 2nd and 3ord order moments)

getK(self) float

Access to partial invariant K (see [2]).

getMomentVector(self) list[float]

To get all the invariant values as a whole.

getObject(self) visp._visp.core.MomentObject
getS(self, i: int) float

Access to partial invariant S (see [2]).

getSN(self, i: int) float

Getter for s (calculated from normalized 2nd and 3ord order moments)

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>

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;
}
name(self) str

Moment name.

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

Parameters:
index: int

index of the temporary invariant

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] [40]

update(self, object: visp._visp.core.MomentObject) None

Updates the moment with the current object. This does not compute any values.