Moment

class Moment

Bases: pybind11_object

This class defines shared methods/attributes for 2D moments.

All moments or combination of moments in the moments module are based on this class. A moment uses a vpMomentObject object to access all useful information. Moment values are obtained by a 4-step process common for all moment types:

  • Declaration.

    vpMoment moment;
    
  • Update with object.

    moment.update(object);
    
  • Compute the moment value

    moment.compute();
    
  • Access the values:

    std::vector<double> values = moment.get();
    

A moment may also be linked to a vpMomentDatabase . Moments linked to a database are able to access each others values. Some moments can be computed only if they are linked to a a database containing their dependencies. Linking to a database is done using the vpMoment::linkTo(…) method.

There are no constraints about format of the array returned by vpMoment::get() ; any implementation is fine.

Each moment must have a string name by implementing the char* vpMoment::name() method which allows to identify the moment in the database. Each moment must also implement a compute method describing how to obtain its values from the object.

Warning

Order of moment computation DOES matter: when you compute a moment using vpMoment::compute() , all moment dependencies must be computed. We recall that implemented moments are:

  • vpMomentAlpha

  • vpMomentArea

  • vpMomentAreaNormalized

  • vpMomentBasic

  • vpMomentCentered

  • vpMomentCInvariant

  • vpMomentGravityCenter

  • vpMomentGravityCenterNormalized

Methods

__init__

get

return:

vector of values

getObject

linkTo

Links the moment to a database of moment primitives.

printDependencies

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

update

Updates the moment with the current object.

Inherited Methods

Operators

__doc__

__init__

__module__

__repr__

Attributes

__annotations__

__init__(*args, **kwargs)
get(self) 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(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.