39#ifndef _vpMomentAlpha_h_
40#define _vpMomentAlpha_h_
42#include <visp3/core/vpMoment.h>
103 vpMomentObject objRef(3); // Reference object. Must be of order 3 because we will
104 // need the 3rd order centered moments
106 objRef.setType(vpMomentObject::DENSE_POLYGON); // Object is the inner part of a polygon
107 objRef.fromVector(vec_p); // Init the dense object with the polygon
109 vpMomentDatabase dbRef; // Reference database
110 vpMomentGravityCenter gRef; // Declaration of gravity center
111 vpMomentCentered mcRef; // Centered moments
112 vpMomentAlpha alphaRef; // Declare alpha as reference
114 gRef.linkTo(dbRef); // Add gravity center to database
115 mcRef.linkTo(dbRef); // Add centered moments
116 alphaRef.linkTo(dbRef); // Add alpha depending on centered moments
118 dbRef.updateAll(objRef); // All of the moments must be updated, not just alpha
120 gRef.compute(); // Compute the moment
121 mcRef.compute(); // Compute centered moments AFTER gravity center
122 alphaRef.compute(); // Compute alpha AFTER centered moments.
124 // The order of values in the vector must be as follows: mu30 mu21 mu12 mu03
125 std::vector<double> mu3ref = {mcRef.get(3,0), mcRef.get(2,1), mcRef.get(1,2), mcRef.get(0,3)};
127 std::cout << "--- Reference object ---" << std::endl;
128 std::cout << "alphaRef=" << vpMath::deg(alphaRef.get()) << " deg" << std::endl << "mu3="; // print reference alpha
129 std::for_each (mu3ref.begin(), mu3ref.end(), print);
130 std::cout << std::endl;
136 p.set_x(-3); p.set_y(1); // Coordinates in meters in the image plane (vertex 4)
138 p.set_x(-3); p.set_y(0); // Coordinates in meters in the image plane (vertex 3)
140 p.set_x(2); p.set_y(-2); // Coordinates in meters in the image plane (vertex 2)
142 p.set_x(1); p.set_y(-1); // Coordinates in meters in the image plane (vertex 1)
145 vpMomentObject obj(3); // Second object. Order 3 is also required because of the Alpha
146 // will compare third-order centered moments to given reference.
148 obj.setType(vpMomentObject::DENSE_POLYGON); // Object is the inner part of a polygon
149 obj.fromVector(vec_p); // Init the dense object with the polygon
151 vpMomentDatabase db; // Database
152 vpMomentGravityCenter g; // Declaration of gravity center
153 vpMomentCentered mc; // mc contains centered moments
154 vpMomentAlpha alpha(mu3ref, alphaRef.get()); // Declare alpha as relative to a reference
156 g.linkTo(db); // Add gravity center to database
157 mc.linkTo(db); // Add centered moments
158 alpha.linkTo(db); // Add alpha depending on centered moments
160 db.updateAll(obj); // All of the moments must be updated
162 g.compute(); // Compute the moment
163 mc.compute(); // Compute centered moments AFTER gravity center
164 alpha.compute(); // Compute alpha AFTER centered moments.
166 std::cout << "--- current object ---" << std::endl;
167 std::cout << "alpha=" << vpMath::deg(alpha.get()) << " deg" << std::endl;
174--- Reference object ---
176mu3=1.80552 0.921882 0.385828 0.122449
177--- current object ---
181 There is also testMomentAlpha.cpp example that shows how to compute alpha in the range \f$ [-\pi ; \pi] \f$
182 using arrow images as input. The code is given below:
183 \include testMomentAlpha.cpp
185 From the first image we compute the 3rd order centered moments and the value of the reference alpha
186 that is than used to compute the alpha moment in the range \f$ [-\pi ; \pi] \f$. Running this example you will get:
188alpha expected 0 computed -0.128108 deg
189alpha expected 45 computed 44.8881 deg
190alpha expected 90 computed 89.8719 deg
191alpha expected 135 computed 134.888 deg
192alpha expected 180 computed 179.872 deg
193alpha expected -135 computed -135.112 deg
194alpha expected -90 computed -90.1281 deg
195alpha expected -45 computed -45.1119 deg
198 Shortcuts for quickly getting those references exist in vpMomentCommon.
200 This moment depends on vpMomentCentered.
207 std::vector<double> m_mu3Ref;
209 double m_symmetricThreshold;
213 vpMomentAlpha(
const std::vector<double> &mu3_ref,
double alpha_ref,
double threshold = 1e-6);
224 const char *
name()
const {
return "vpMomentAlpha"; }
This class defines the orientation of the object inside the plane parallel to the object.
bool is_symmetric() const
const char * name() const
std::vector< double > values
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpMoment &m)
virtual void printDependencies(std::ostream &os) const