![]() |
Visual Servoing Platform version 3.7.0
|
#include <vpMomentObject.h>
Public Types | |
| enum | vpObjectType { DENSE_FULL_OBJECT = 0 , DENSE_POLYGON = 1 , DISCRETE = 2 } |
| enum | vpCameraImgBckGrndType { BLACK = 0 , WHITE = 1 } |
Public Member Functions | |
| VP_EXPLICIT | vpMomentObject (unsigned int order) |
| vpMomentObject (const vpMomentObject &srcobj) | |
| virtual | ~vpMomentObject () |
| vpMomentObject & | operator= (const vpMomentObject &)=default |
| void | fromImage (const vpImage< unsigned char > &image, unsigned char threshold, const vpCameraParameters &cam) |
| void | fromImage (const vpImage< unsigned char > &image, const vpCameraParameters &cam, vpCameraImgBckGrndType bg_type, bool normalize_with_pix_size=true) |
| void | fromVector (std::vector< vpPoint > &points) |
| const std::vector< double > & | get () const |
| double | get (unsigned int i, unsigned int j) const |
| vpObjectType | getType () const |
| unsigned int | getOrder () const |
| void | init (unsigned int orderinp) |
| void | init (const vpMomentObject &objin) |
| void | setType (vpObjectType input_type) |
Static Public Member Functions | |
| static void | printWithIndices (const vpMomentObject &momobj, std::ostream &os) |
| static vpMatrix | convertTovpMatrix (const vpMomentObject &momobj) |
Public Attributes | |
| bool | flg_normalize_intensity |
Protected Member Functions | |
| void | set (unsigned int i, unsigned int j, const double &value_ij) |
| void | cacheValues (std::vector< double > &cache, double x, double y) |
Protected Attributes | |
| unsigned int | order |
| vpObjectType | type |
| std::vector< double > | values |
Friends | |
| VISP_EXPORT std::ostream & | operator<< (std::ostream &os, const vpMomentObject &v) |
Class for generic objects.
It contains all basic moments often described by
of order
going from
to the order used as parameter in vpMomentObject() constructor. All other moments implemented in ViSP (gravity center, alpha orientation, centered moments...) use this moment object as a combination of its different values.
When constructing a vpMomentObject() you need first to specify the maximum used moment order as parameter.
Then there are three ways to initialize a vpMomentObject. Firstly using fromImage() you can considerer a dense object O defined by an image. Secondly, as described in fromVector() you can also define a dense object O by a closed contour. In these two cases, 2D basic moments are defined by:
Lastly, as presented in fromVector() you can consider a discrete set of n points. In that last case, the basic moments are defined by
With setType() method you can specify the object type.
The implementation is based on the following references [52], [6], [54], [2].
A few tips about which orders to use in different situations:
The following example shows how to create a moment object from 4 discrete points locate on a plane one meter in front of the camera. It shows also how to get the basic moments that are computed and how to compute other classical moments such as the gravity center or the centered moments.
This example produces the following results:
Note that in the continuous case, the moment object
corresponds to the surface
of the object. In the discrete case, it is the number of discrete points
.
Definition at line 224 of file vpMomentObject.h.
Type of camera image background.
| Enumerator | |
|---|---|
| BLACK | Black background. |
| WHITE | Not functional right now. |
Definition at line 243 of file vpMomentObject.h.
Type of object that will be considered.
Definition at line 230 of file vpMomentObject.h.
| vpMomentObject::vpMomentObject | ( | unsigned int | max_order | ) |
Default constructor. Initializes the object with the maximum used order. You cannot use higher order moments than the order of the moment object. The parameter specified is the highest desired included order. All orders up to this values will be computed. In other words, a vpMomentObject will compute all
moments with
.
| max_order | : Maximum reached order (i+j) to be used. All considered i+j will be of order smaller or equal than this parameter. For example if this parameter is 5, all moment values of order 0 to 5 included will be computed. |
Mani : outsourced the constructor work to void init (unsigned int orderinp);
Definition at line 502 of file vpMomentObject.cpp.
References DENSE_FULL_OBJECT, flg_normalize_intensity, init(), order, type, values, and vpMomentObject().
Referenced by convertTovpMatrix(), init(), operator<<, operator=(), printWithIndices(), vpMomentObject(), and vpMomentObject().
| vpMomentObject::vpMomentObject | ( | const vpMomentObject & | srcobj | ) |
Copy constructor
Definition at line 511 of file vpMomentObject.cpp.
References DENSE_FULL_OBJECT, flg_normalize_intensity, init(), order, type, values, and vpMomentObject().
|
virtual |
Virtual destructor to allow polymorphic usage. For instance,
where vpWeightedMomentObject is child class of vpMomentObject
Nothing to destruct. This will allow for a polymorphic usage For instance,
where vpWeightedMomentObject is child class of vpMomentObject
Definition at line 638 of file vpMomentObject.cpp.
|
protected |
Caching to avoid redundant multiplications.
| cache | : Lookup table that contains the order by order values. For example, if the order is 3, cache will contain: 1 x x^2
y x*y x^2*y
y^2 x*y^2 x^2*y^2
|
| x | : Coordinate of a point along x-axis. |
| y | : Coordinate of a point along y-axis. |
Definition at line 108 of file vpMomentObject.cpp.
References order.
Referenced by fromImage(), fromImage(), and fromVector().
|
static |
Converts the raw moments contained in vpMomentObject to a vpMatrix
| momobj | : A vpMomentObject |
This function returns a vpMatrix of size (order+1, order+1).
Instead of accessing the moment m21 as obj.get(2,1), you can now do Mpq[2][1]. This is useful when you want to use the functions available in vpMatrix. One use case i see now is to copy the contents of the matrix to a file or std::cout. For instance, like
The output can be copied and pasted to MAPLE as a matrix.
Definition at line 617 of file vpMomentObject.cpp.
References get(), getOrder(), order, and vpMomentObject().
| void vpMomentObject::fromImage | ( | const vpImage< unsigned char > & | image, |
| const vpCameraParameters & | cam, | ||
| vpCameraImgBckGrndType | bg_type, | ||
| bool | normalize_with_pix_size = true ) |
Computes basic moments from an image based on this reference [2].
Intended to be used by vpMomentObject with DENSE_FULL_OBJECT object type, see setType().
| image | : Grayscale image |
| cam | : Camera parameters (to change to ) |
| bg_type | : White/Black background surrounding the image |
| normalize_with_pix_size | : When this flag if set, the moments, after calculation are normalized w.r.t pixel size available from camera parameters. |
Definition at line 379 of file vpMomentObject.cpp.
References cacheValues(), vpPixelMeterConversion::convertPoint(), flg_normalize_intensity, vpImage< Type >::getCols(), vpImage< Type >::getRows(), order, values, and WHITE.
| void vpMomentObject::fromImage | ( | const vpImage< unsigned char > & | image, |
| unsigned char | threshold, | ||
| const vpCameraParameters & | cam ) |
Computes basic moments from an image based on this reference [2].
There is no assumption made about whether the input is dense or discrete but it's more common to use vpMomentObject::DENSE_FULL_OBJECT with this method.
| image | : Image to consider. |
| threshold | : Pixels with a luminance lower than this threshold will be considered. |
| cam | : Camera parameters used to convert pixels coordinates in meters in the image plane. |
The code below shows how to use this function.
Definition at line 296 of file vpMomentObject.cpp.
References cacheValues(), vpPixelMeterConversion::convertPoint(), vpImage< Type >::getCols(), vpImage< Type >::getRows(), order, and values.
Referenced by operator=().
| void vpMomentObject::fromVector | ( | std::vector< vpPoint > & | points | ) |
Computes basic moments from a vector of points. There are two cases:
| points | : Vector of points. |
The code below shows how to use this function to consider a dense object defined by a closed contour.
This other example shows how to consider an object as a discrete set of four points.
Definition at line 232 of file vpMomentObject.cpp.
References cacheValues(), DENSE_POLYGON, order, type, and values.
Referenced by operator=().
| const std::vector< double > & vpMomentObject::get | ( | ) | const |
Returns all basic moment values
with
and
.
For example, if the maximal order is 3, the following values are provided:
To access for example to the basic moment m12, you should use this kind of code:
Definition at line 538 of file vpMomentObject.cpp.
References values.
Referenced by vpMomentArea::compute(), vpMomentAreaNormalized::compute(), vpMomentCentered::compute(), vpMomentCInvariant::compute(), vpMomentGravityCenter::compute(), vpFeatureMomentArea::compute_interaction(), vpFeatureMomentAreaNormalized::compute_interaction(), vpFeatureMomentBasic::compute_interaction(), vpFeatureMomentCentered::compute_interaction(), vpFeatureMomentCInvariant::compute_interaction(), vpFeatureMomentGravityCenter::compute_interaction(), vpFeatureMomentGravityCenterNormalized::compute_interaction(), convertTovpMatrix(), vpMomentBasic::get(), vpMomentBasic::get(), operator=(), vpMomentAreaNormalized::printDependencies(), vpMomentGravityCenter::printDependencies(), and printWithIndices().
| double vpMomentObject::get | ( | unsigned int | i, |
| unsigned int | j ) const |
Returns the basic moment value
corresponding to i,j indexes
| i | : First moment index, with |
| j | : Second moment index, with |
Definition at line 546 of file vpMomentObject.cpp.
References vpException::badValue, getOrder(), order, and values.
|
inline |
Definition at line 288 of file vpMomentObject.h.
References order.
Referenced by vpMomentCentered::compute(), vpFeatureMomentBasic::compute_interaction(), vpFeatureMomentCentered::compute_interaction(), convertTovpMatrix(), vpMomentCentered::get(), get(), init(), vpMomentCentered::operator<<, vpMomentCentered::printWithIndices(), printWithIndices(), vpMomentCentered::set(), and set().
|
inline |
Definition at line 282 of file vpMomentObject.h.
References type.
Referenced by vpFeatureMomentAlpha::compute_interaction(), vpFeatureMomentArea::compute_interaction(), vpFeatureMomentAreaNormalized::compute_interaction(), vpFeatureMomentBasic::compute_interaction(), vpFeatureMomentCentered::compute_interaction(), vpFeatureMomentCInvariant::compute_interaction(), vpFeatureMomentGravityCenter::compute_interaction(), vpFeatureMomentGravityCenterNormalized::compute_interaction(), and init().
| void vpMomentObject::init | ( | const vpMomentObject & | objin | ) |
Helper to copy constructor.
Definition at line 478 of file vpMomentObject.cpp.
References flg_normalize_intensity, getOrder(), getType(), order, type, values, and vpMomentObject().
| void vpMomentObject::init | ( | unsigned int | orderinp | ) |
Does exactly the work of the default constructor as it existed in the very first version of vpMomentObject.
Definition at line 466 of file vpMomentObject.cpp.
References DENSE_FULL_OBJECT, flg_normalize_intensity, order, type, and values.
Referenced by vpMomentObject(), and vpMomentObject().
|
default |
References fromImage(), fromVector(), get(), and vpMomentObject().
|
static |
Outputs raw moments in indexed form like m[1,1] = value of moment m11
| momobj | : A vpMomentObject |
| os | : Output stream. |
Outputs the raw moment values
in indexed form. The moment values are same as provided by the operator << which outputs x for uncalculated moments.
Definition at line 577 of file vpMomentObject.cpp.
References get(), getOrder(), and vpMomentObject().
Referenced by vpMomentBasic::operator<<, vpMomentBasic::printDependencies(), and vpMomentCentered::printDependencies().
|
protected |
Sets the basic moment value
corresponding to i,j indexes
| i | : First moment index, with |
| j | : Second moment index, with |
| value_ij | : Moment value. |
Definition at line 563 of file vpMomentObject.cpp.
References vpException::badValue, getOrder(), order, and values.
|
inline |
Specifies the type of the input data.
| input_type | : An input type. |
Definition at line 305 of file vpMomentObject.h.
References type.
|
friend |
Outputs the basic moment's values
to a stream presented as a matrix. The first line corresponds to
, the second one to
Values in table corresponding to a higher order are marked with an "x" and not computed.
For example, if the maximal order is 3, the following values are provided:
Definition at line 658 of file vpMomentObject.cpp.
References operator<<, order, values, and vpMomentObject().
Referenced by operator<<.
| bool vpMomentObject::flg_normalize_intensity |
Definition at line 249 of file vpMomentObject.h.
Referenced by fromImage(), init(), init(), vpMomentObject(), and vpMomentObject().
|
protected |
Definition at line 314 of file vpMomentObject.h.
Referenced by cacheValues(), convertTovpMatrix(), fromImage(), fromImage(), fromVector(), get(), getOrder(), init(), init(), operator<<, set(), vpMomentObject(), and vpMomentObject().
|
protected |
Definition at line 315 of file vpMomentObject.h.
Referenced by fromVector(), getType(), init(), init(), setType(), vpMomentObject(), and vpMomentObject().
|
protected |
Definition at line 316 of file vpMomentObject.h.
Referenced by fromImage(), fromImage(), fromVector(), get(), get(), init(), init(), operator<<, set(), vpMomentObject(), and vpMomentObject().