34 #include <visp3/core/vpConfig.h>
39 #include <visp3/core/vpMomentCentered.h>
40 #include <visp3/core/vpMomentGravityCenter.h>
41 #include <visp3/core/vpMomentObject.h>
42 #include <visp3/visual_features/vpFeatureMomentBasic.h>
43 #include <visp3/visual_features/vpFeatureMomentCentered.h>
44 #include <visp3/visual_features/vpFeatureMomentDatabase.h>
45 #include <visp3/visual_features/vpFeatureMomentGravityCenter.h>
70 "been computed, you should "
71 "specify a higher order.");
92 double pcombkqcombl = 0.0;
98 double minus1pow = 0.;
101 for (
unsigned int k = 0; k <= p; ++k) {
102 int pmk = (int)p - (
int)k;
103 double pcombk =
static_cast<double>(
vpMath::comb(p, k));
104 for (
unsigned int l = 0; l <= q; ++l) {
105 qml = (int)q - (
int)l;
107 minus1pow = pow((
double)-1, (
double)(pmk + qml));
108 pcombkqcombl = pcombk * qcombl;
110 pintom = pcombkqcombl * mkl;
113 term1 += pintom * pmk * pow(xg, pmk - 1) * pow(yg, qml) * minus1pow;
115 term2 += pintom * qml * pow(xg, pmk) * pow(yg, qml - 1) * minus1pow;
116 Lterm3 += pcombkqcombl * pow(xg, pmk) * pow(yg, qml) * L_mkl * minus1pow;
122 vpMatrix L_mupq = L_xg * term1 + L_yg * term2 + Lterm3;
140 #ifdef VISP_MOMENTS_COMBINE_MATRICES
147 bool found_moment_gravity;
150 if (!found_moment_gravity)
152 double xg = momentGravity.
get()[0];
153 double yg = momentGravity.
get()[1];
155 bool found_feature_gravity_center;
158 if (!found_feature_gravity_center)
163 bool found_moment_basic;
166 if (!found_moment_basic)
169 bool found_featuremoment_basic;
172 if (!found_featuremoment_basic)
176 for (
int i = 0; i < (int)
order - 1; i++) {
177 for (
int j = 0; j < (int)
order - 1 - i; j++) {
179 compute_Lmu_pq(i, j, xg, yg, Lxg, Lyg, momentbasic, featureMomentBasic);
183 bool found_moment_centered;
184 bool found_moment_gravity;
191 if (!found_moment_centered)
193 if (!found_moment_gravity)
211 double n11 = momentCentered.
get(1, 1) / momentObject.
get(0, 0);
212 double n20 = momentCentered.
get(2, 0) / momentObject.
get(0, 0);
213 double n02 = momentCentered.
get(0, 2) / momentObject.
get(0, 0);
214 double Xg = momentGravity.
getXg();
215 double Yg = momentGravity.
getYg();
216 double mu00 = momentCentered.
get(0, 0);
238 for (
int i = 1; i < (int)
order - 1; i++) {
239 unsigned int i_ = (
unsigned int)i;
240 unsigned int im1_ = i_ - 1;
241 unsigned int ip1_ = i_ + 1;
243 double mu_im10 = momentCentered.
get(im1_, 0);
244 double mu_ip10 = momentCentered.
get(ip1_, 0);
245 double mu_im11 = momentCentered.
get(im1_, 1);
246 double mu_i0 = momentCentered.
get(i_, 0);
247 double mu_i1 = momentCentered.
get(i_, 1);
253 (i + 3 * delta) * mu_i1 + (i + 3 * delta) * Yg * mu_i0 + i * Xg * mu_im11 - i * epsilon * n11 * mu_im10;
255 -(i + 3 * delta) * mu_ip10 - (2 * i + 3 * delta) * Xg * mu_i0 + i * epsilon * n20 * mu_im10;
261 for (
int j = 1; j < (int)
order - 1; j++) {
262 unsigned int j_ = (
unsigned int)j;
263 unsigned int jm1_ = j_ - 1;
264 unsigned int jp1_ = j_ + 1;
266 double mu_0jm1 = momentCentered.
get(0, jm1_);
267 double mu_0jp1 = momentCentered.
get(0, jp1_);
268 double mu_1jm1 = momentCentered.
get(1, jm1_);
269 double mu_0j = momentCentered.
get(0, j_);
270 double mu_1j = momentCentered.
get(1, j_);
276 (j + 3 * delta) * mu_0jp1 + (2 * j + 3 * delta) * Yg * mu_0j - j * epsilon * n02 * mu_0jm1;
278 -(j + 3 * delta) * mu_1j - (j + 3 * delta) * Xg * mu_0j - j * Yg * mu_1jm1 + j * epsilon * n11 * mu_0jm1;
284 for (
int j = 1; j < (int)
order - 1; j++) {
285 unsigned int j_ = (
unsigned int)j;
286 unsigned int jm1_ = j_ - 1;
287 unsigned int jp1_ = j_ + 1;
288 for (
int i = 1; i < (int)
order - j - 1; i++) {
289 unsigned int i_ = (
unsigned int)i;
290 unsigned int im1_ = i_ - 1;
291 unsigned int ip1_ = i_ + 1;
293 double mu_ijm1 = momentCentered.
get(i_, jm1_);
294 double mu_ij = momentCentered.
get(i_, j_);
295 double mu_ijp1 = momentCentered.
get(i_, jp1_);
296 double mu_im1j = momentCentered.
get(im1_, j_);
297 double mu_im1jp1 = momentCentered.
get(im1_, jp1_);
298 double mu_ip1jm1 = momentCentered.
get(ip1_, jm1_);
299 double mu_ip1j = momentCentered.
get(ip1_, j_);
305 (i + 2 * j + 3 * delta) * Yg * mu_ij + i * Xg * mu_im1jp1 -
306 i * epsilon * n11 * mu_im1j - j * epsilon * n02 * mu_ijm1;
308 (2 * i + j + 3 * delta) * Xg * mu_ij - j * Yg * mu_ip1jm1 +
309 i * epsilon * n20 * mu_im1j + j * epsilon * n11 * mu_ijm1;
312 (i + j + 2 * delta) *
C * mu_ij;
325 vpTRACE(
" << Ls - CENTRED MOMENTS >>");
326 unsigned int order_m_1 = (
unsigned int)(mu.
order - 1);
327 for (
unsigned int i = 0; i < order_m_1; i++) {
328 for (
unsigned int j = 0; j < order_m_1 - i; j++) {
329 os <<
"L_mu[" << i <<
"," << j <<
"] = ";
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
@ notInitialized
Used to indicate that a parameter is not initialized.
Functionality computation for basic moment feature. Computes the interaction matrix associated with v...
vpMatrix interaction(unsigned int select_one, unsigned int select_two) const
Functionality computation for centered moment feature. Computes the interaction matrix associated wit...
void compute_interaction() vp_override
vpFeatureMomentCentered(vpMomentDatabase &moments, double A, double B, double C, vpFeatureMomentDatabase *featureMoments=nullptr)
vpMatrix interaction(unsigned int select_one, unsigned int select_two) const
vpMatrix compute_Lmu_pq(const unsigned int &p, const unsigned int &q, const double &xg, const double &yg, const vpMatrix &L_xg, const vpMatrix &L_yg, const vpMomentBasic &m, const vpFeatureMomentBasic &feature_moment_m) const
This class allows to register all feature moments (implemented in vpFeatureMoment....
vpFeatureMoment & get(const std::string &feature_name, bool &found)
Functionality computation for gravity center moment feature. Computes the interaction matrix associat...
This class defines shared system methods/attributes for 2D moment features but no functional code....
std::vector< vpMatrix > interaction_matrices
vpMatrix interaction(unsigned int select=FEATURE_ALL) vp_override
vpFeatureMomentDatabase * featureMomentsDataBase
vpMomentDatabase & moments
static long double comb(unsigned int n, unsigned int p)
Implementation of a matrix and operations on matrices.
std::ostream & matlabPrint(std::ostream &os) const
This class defines the 2D basic moment . This class is a wrapper for vpMomentObject wich allows to us...
const std::vector< double > & get() const
This class defines the double-indexed centered moment descriptor .
double get(unsigned int i, unsigned int j) const
This class allows to register all vpMoments so they can access each other according to their dependen...
const vpMoment & get(const std::string &moment_name, bool &found) const
Class describing 2D gravity center moment.
const std::vector< double > & get() const
Class for generic objects.
unsigned int getOrder() const
const std::vector< double > & get() const
vpObjectType getType() const
const vpMomentObject & getObject() const