Visual Servoing Platform
version 3.2.0 under development (2019-01-22)
|
#include <visp3/core/vpMomentObject.h>
Public Types | |
enum | vpObjectType { DENSE_FULL_OBJECT = 0, DENSE_POLYGON = 1, DISCRETE = 2 } |
enum | vpCameraImgBckGrndType { BLACK = 0, WHITE = 1 } |
Public Member Functions | |
vpMomentObject (unsigned int order) | |
vpMomentObject (const vpMomentObject &srcobj) | |
virtual | ~vpMomentObject () |
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 a binary 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.
A few tips about which orders to use in different situations: - moment based visual servoing: use vpMomentObject(6). This will computemoment values up to order 6 which will enable vpFeatureMoments up to order 5 which is the maximum order required for common moments.
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 219 of file vpMomentObject.h.
Type of camera image background.
Enumerator | |
---|---|
BLACK | |
WHITE |
Black background |
Definition at line 237 of file vpMomentObject.h.
Type of object that will be considered.
Definition at line 225 of file vpMomentObject.h.
|
explicit |
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 495 of file vpMomentObject.cpp.
References init().
vpMomentObject::vpMomentObject | ( | const vpMomentObject & | srcobj | ) |
|
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 667 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,y | : Coordinates of a point. |
Definition at line 111 of file vpMomentObject.cpp.
References order.
Referenced by 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 646 of file vpMomentObject.cpp.
References get(), getOrder(), and order.
void vpMomentObject::fromImage | ( | const vpImage< unsigned char > & | image, |
unsigned char | threshold, | ||
const vpCameraParameters & | cam | ||
) |
Computes basic moments from an image. 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 289 of file vpMomentObject.cpp.
References cacheValues(), vpPixelMeterConversion::convertPoint(), vpCameraParameters::get_px(), vpCameraParameters::get_py(), vpImage< Type >::getCols(), vpImage< Type >::getRows(), order, and values.
void vpMomentObject::fromImage | ( | const vpImage< unsigned char > & | image, |
const vpCameraParameters & | cam, | ||
vpCameraImgBckGrndType | bg_type, | ||
bool | normalize_with_pix_size = true |
||
) |
Manikandan. B Photometric moments v2 Intended to be used by 'vpMomentObject's of type DENSE_FULL_OBJECT
image | : Grayscale image |
cam | : Camera parameters (to change to ) |
bg_type | : White/Black background surrounding the image |
normalize_with_pix_size | : This flag if SET, the moments, after calculation are normalized w.r.t pixel size available from camera parameters |
Definition at line 373 of file vpMomentObject.cpp.
References cacheValues(), vpPixelMeterConversion::convertPoint(), flg_normalize_intensity, vpCameraParameters::get_px(), vpCameraParameters::get_py(), vpImage< Type >::getCols(), vpImage< Type >::getRows(), order, values, and WHITE.
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 230 of file vpMomentObject.cpp.
References cacheValues(), DENSE_POLYGON, order, type, and values.
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 532 of file vpMomentObject.cpp.
References values.
Referenced by vpMomentArea::compute(), vpMomentCentered::compute(), vpMomentGravityCenter::compute(), vpMomentAreaNormalized::compute(), vpMomentCInvariant::compute(), vpFeatureMomentArea::compute_interaction(), vpFeatureMomentBasic::compute_interaction(), vpFeatureMomentCentered::compute_interaction(), vpFeatureMomentAreaNormalized::compute_interaction(), vpFeatureMomentGravityCenter::compute_interaction(), vpFeatureMomentCInvariant::compute_interaction(), vpFeatureMomentGravityCenterNormalized::compute_interaction(), convertTovpMatrix(), vpMomentBasic::get(), vpMomentGravityCenter::printDependencies(), vpMomentAreaNormalized::printDependencies(), printWithIndices(), and vpMomentCInvariant::vpMomentCInvariant().
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 540 of file vpMomentObject.cpp.
References vpException::badValue, getOrder(), order, and values.
|
inline |
Definition at line 277 of file vpMomentObject.h.
Referenced by vpMomentCentered::compute(), vpFeatureMomentBasic::compute_interaction(), vpFeatureMomentCentered::compute_interaction(), convertTovpMatrix(), vpMomentCentered::get(), get(), init(), vpFeatureMomentBasic::interaction(), vpFeatureMomentCentered::interaction(), vpMomentCentered::printWithIndices(), printWithIndices(), vpMomentCentered::set(), and set().
|
inline |
Definition at line 271 of file vpMomentObject.h.
Referenced by vpFeatureMomentArea::compute_interaction(), vpFeatureMomentBasic::compute_interaction(), vpFeatureMomentCentered::compute_interaction(), vpFeatureMomentAlpha::compute_interaction(), vpFeatureMomentAreaNormalized::compute_interaction(), vpFeatureMomentGravityCenter::compute_interaction(), vpFeatureMomentCInvariant::compute_interaction(), vpFeatureMomentGravityCenterNormalized::compute_interaction(), init(), and vpMomentCInvariant::vpMomentCInvariant().
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 459 of file vpMomentObject.cpp.
References DENSE_FULL_OBJECT, flg_normalize_intensity, order, type, and values.
Referenced by vpMomentObject().
void vpMomentObject::init | ( | const vpMomentObject & | objin | ) |
Helper to copy constructor
Definition at line 471 of file vpMomentObject.cpp.
References flg_normalize_intensity, getOrder(), getType(), order, type, and values.
|
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 605 of file vpMomentObject.cpp.
References get(), and getOrder().
Referenced by 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 557 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 294 of file vpMomentObject.h.
|
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 582 of file vpMomentObject.cpp.
bool vpMomentObject::flg_normalize_intensity |
Definition at line 242 of file vpMomentObject.h.
Referenced by fromImage(), and init().
|
protected |
Definition at line 303 of file vpMomentObject.h.
Referenced by cacheValues(), convertTovpMatrix(), fromImage(), fromVector(), get(), init(), and set().
|
protected |
Definition at line 304 of file vpMomentObject.h.
Referenced by fromVector(), and init().
|
protected |
Definition at line 305 of file vpMomentObject.h.
Referenced by fromImage(), fromVector(), get(), init(), and set().