MomentCentered

class MomentCentered(self)

Bases: Moment

This class defines the double-indexed centered moment descriptor \(\mu_{ij}\) .

In the case of a dense object O , centered moments are defined by:

\[\mu_{ij}= \int \int_{O} (x_k-x_g)^j (y_k-y_g)^j\]

In the case of a discrete set of n points, centered moments are defined by:

\[\mu_{ij}= \sum_{k=1}^{n} (x_k-x_g)^j (y_k-y_g)^j\]

where \((x_g,y_g)\) are the coordinates of the center of gravity.

The centered moments are computed from the object at the highest possible order. For example if the vpMomentObject is defined up to order 5, vpMomentCentered will be too.

Values of vpMomentCentered may be accessed by one of the two vpMomentCentered::get methods. When using vpMomentCentered::get (), the format of the return vector is the following: \(\mu_{ij}\) is stored at vpMomentCentered::get ()[j* ( vpMomentObject::getOrder () +1)+i]

vpMomentCentered depends on vpMomentGravityCenter .

Default constructor.

Methods

__init__

Default constructor.

compute

Computes centered moments of all available orders.

get

Overloaded function.

name

Moment name.

printDependencies

Overloaded function.

printWithIndices

Print in a readable form which looks better than output from << operator

Inherited Methods

linkTo

Links the moment to a database of moment primitives.

getObject

update

Updates the moment with the current object.

Operators

__doc__

__init__

Default constructor.

__module__

__repr__

Attributes

__annotations__

__init__(self)

Default constructor.

compute(self) None

Computes centered moments of all available orders. Depends on vpMomentGravityCenter .

get(*args, **kwargs)

Overloaded function.

  1. get(self: visp._visp.core.MomentCentered, i: int, j: int) -> float

Parameters:
i

first index of the centered moment.

j

second index of the centered moment.

Returns:

\(\mu_{ij}\) moment.

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

Returns all centered moment values \(\mu_{ij}\) with \(i+j \leq order\) where order is the object’s order.

For example, if the maximal order is 3, the following values are provided:

u00 u10 u20 u01 u11 u21 u02 u12 u12 u30 u03

To have a better reading of the moments you can picture them as a triangular matrix:

u00 u10 u20 u30 u01 u11 u21 x u02 u12  x  x u30 x    x  x

The moments of the same order are on each of the matrix reverse diagonals. To access for example to the centered moment \(\mu_{12}\) , you should use this kind of code:

vpMomentCentered mc;
//[...]
mc.compute();
double mu12;
mu12 = mc.get()[2*(obj.getOrder()+1)+1]; // i=1 and j=2
mu12 = mc.get(1,2); // the same
Returns:

Vector of moment values. To access \(\mu_{ij}\) , you have to read vpMomentObject::get() [j*order+i].

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

Moment name.

printDependencies(*args, **kwargs)

Overloaded function.

  1. printDependencies(self: visp._visp.core.MomentCentered, os: std::ostream) -> None

<unparsed orderedlist <doxmlparser.compound.docListType object at 0x7f4224750b80>>

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

printWithIndices(self: visp._visp.core.MomentCentered, os: std::ostream) None

Print in a readable form which looks better than output from << operator

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

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