40 #include <visp3/core/vpMomentCInvariant.h>
41 #include <visp3/core/vpMomentCentered.h>
42 #include <visp3/core/vpMomentObject.h>
49 : I(16), II(4), c(4), s(4), K(0.0), cn(4), sn(4), In1(0.0), flg_sxsynormalization_(flg_sxsynormalization)
59 void vpMomentCInvariant::computeI(
const vpMomentCentered &momentCentered, std::vector<double> &I_val)
62 double mu30 = momentCentered.
get(3, 0);
63 double mu30_2 = mu30 * mu30;
64 double mu30_3 = mu30_2 * mu30;
66 double mu03 = momentCentered.
get(0, 3);
67 double mu03_2 = mu03 * mu03;
68 double mu03_3 = mu03 * mu03_2;
70 double mu20 = momentCentered.
get(2, 0);
71 double mu02 = momentCentered.
get(0, 2);
72 double mu50 = momentCentered.
get(5, 0);
73 double mu32 = momentCentered.
get(3, 2);
74 double mu14 = momentCentered.
get(1, 4);
75 double mu05 = momentCentered.
get(0, 5);
76 double mu23 = momentCentered.
get(2, 3);
77 double mu41 = momentCentered.
get(4, 1);
78 double mu40 = momentCentered.
get(4, 0);
79 double mu04 = momentCentered.
get(0, 4);
80 double mu31 = momentCentered.
get(3, 1);
81 double mu13 = momentCentered.
get(1, 3);
82 double mu22 = momentCentered.
get(2, 2);
83 double mu21 = momentCentered.
get(2, 1);
84 double mu12 = momentCentered.
get(1, 2);
85 double mu11 = momentCentered.
get(1, 1);
87 double mu11_2 = mu11 * mu11;
88 double mu12_2 = mu12 * mu12;
89 double mu21_2 = mu21 * mu21;
90 double mu22_2 = mu22 * mu22;
91 double mu13_2 = mu13 * mu13;
92 double mu31_2 = mu31 * mu31;
93 double mu04_2 = mu04 * mu04;
94 double mu40_2 = mu40 * mu40;
95 double mu21_3 = mu21 * mu21_2;
96 double mu12_3 = mu12_2 * mu12;
97 double mu12_4 = mu12_3 * mu12;
98 double mu21_4 = mu21_2 * mu21_2;
102 double zeta = mu20 - mu02;
103 double zeta_2 = zeta * zeta;
104 double omicron = (mu03_2 + 3 * mu03 * mu21 + mu30 * (mu30 + 3 * mu12));
105 double omega = mu50 + 2 * mu32 + mu14;
106 double nu = mu05 + 2 * mu23 + mu41;
107 double ro = mu50 - 2 * mu32 - 3 * mu14;
108 double gamma = mu05 - 2 * mu23 - 3 * mu41;
110 double delta = mu50 - 10 * mu32 + 5 * mu14;
111 double phi = mu05 - 10 * mu23 + 5 * mu41;
112 double omega_2 = omega * omega;
113 double nu_2 = nu * nu;
114 double ro_2 = ro * ro;
115 double gamma_2 = gamma * gamma;
116 double delta_2 = delta * delta;
117 double phi_2 = phi * phi;
119 I_val[1] = -mu20 * mu02 + mu11_2;
120 I_val[2] = zeta_2 + 4 * mu11_2;
121 I_val[3] = (mu30 - 3 * mu12) * (mu30 - 3 * mu12) + (mu03 - 3 * mu21) * (mu03 - 3 * mu21);
122 I_val[4] = (mu30 + mu12) * (mu30 + mu12) + (mu21 + mu03) * (mu21 + mu03);
123 I_val[5] = -mu30_2 * mu03_2 + (-4 * mu12_3 + 6 * mu21 * mu12 * mu03) * mu30 - 4 * mu21_3 * mu03 + 3 * mu21_2 * mu12_2;
124 I_val[6] = 3 * mu12_4 + 2 * mu30 * mu12_3 + (3 * mu30_2 - 6 * mu03 * mu21) * mu12_2 -
125 6 * mu30 * mu21 * (mu21 + mu03) * mu12 + 2 * mu30_2 * mu03_2 + 2 * mu21_3 * mu03 + 3 * mu21_2 * mu03_2 +
127 I_val[7] = (3 * mu21 + 2 * mu03) * mu12_3 + 3 * mu30 * (mu03 + 2 * mu21) * mu12_2 -
128 3 * mu21 * (mu30 + mu03 + mu21) * (-mu30 + mu03 + mu21) * mu12 +
129 mu30 * (-mu30_2 * mu03 - 2 * mu21_3 - 3 * mu03 * mu21_2 + mu03_3);
131 I_val[8] = 3 * mu03 * mu21_3 - 2 * mu03_2 * mu21_2 + mu21_2 * mu30_2 + 3 * mu12_2 * mu03 * mu21 -
132 mu03 * mu21 * mu30_2 - mu03_3 * mu21 + 3 * mu12_3 * mu30 - 2 * mu12_2 * mu30_2 + mu12_2 * mu03_2 -
133 mu12 * mu30_3 - mu12 * mu30 * mu03_2 + 3 * mu12 * mu30 * mu21_2 - 6 * mu12 * mu30 * mu03 * mu21;
134 I_val[9] = omicron * omicron;
136 I_val[10] = mu40 * mu04 - 4 * mu31 * mu13 + 3 * mu22_2;
137 I_val[11] = 3 * mu13_2 + 2 * mu31 * mu13 + (-3 * mu40 - 3 * mu04) * mu22 - 2 * mu40 * mu04 + 3 * mu31_2;
138 I_val[12] = 3 * mu04_2 + (2 * mu40 + 12 * mu22) * mu04 + 3 * mu40_2 + 12 * mu40 * mu22 + 16 * mu31 * mu13;
139 I_val[13] = omega_2 + nu_2;
140 I_val[14] = ro_2 + gamma_2;
141 I_val[15] = delta_2 + phi_2;
145 a = momentCentered.
get(2, 0) + momentCentered.
get(0, 2);
149 c[1] = momentCentered.
get(2, 0) - momentCentered.
get(0, 2);
150 s[1] = 2 * momentCentered.
get(1, 1);
151 c[2] = momentCentered.
get(0, 3) - 3 * momentCentered.
get(2, 1);
152 s[2] = momentCentered.
get(3, 0) - 3 * momentCentered.
get(1, 2);
153 c[3] = c[1] * c[1] - s[1] * s[1];
154 s[3] = 2 * s[1] * c[1];
156 II[1] = c[1] * c[1] + s[1] * s[1];
157 II[2] = c[2] * c[2] + s[2] * s[2];
158 II[3] = momentCentered.
get(2, 0) + momentCentered.
get(0, 2);
160 K = (II[1] * (II[3] * sqrt(std::fabs(II[3])))) / sqrt(std::fabs(a));
167 double p20 = momentCentered.
get(2, 0) / II[3];
168 double p11 = momentCentered.
get(1, 1) / II[3];
169 double p02 = momentCentered.
get(0, 2) / II[3];
172 sqrt(std::fabs(a)) / (II[3] * sqrt(std::fabs(II[3])));
173 double p30 = momentCentered.
get(3, 0) * d;
174 double p21 = momentCentered.
get(2, 1) * d;
175 double p12 = momentCentered.
get(1, 2) * d;
176 double p03 = momentCentered.
get(0, 3) * d;
180 sn[2] = p30 - 3.0 * p12;
181 cn[2] = p03 - 3.0 * p21;
183 cn[3] = cn[1] * cn[1] - sn[1] * sn[1];
184 sn[3] = 2.0 * sn[1] * cn[1];
186 In1 = cn[1] * cn[1] + sn[1] * sn[1];
199 "Specify at least order 5.");
200 bool found_moment_centered;
204 if (!found_moment_centered)
207 computeI(momentCentered, I);
208 double II3_2 = II[3] * II[3];
209 double II3_3 = II3_2 * II[3];
213 a = momentCentered.
get(2, 0) + momentCentered.
get(0, 2);
228 values[6] = I[11] / I[10];
230 values[7] = I[12] / I[10];
232 values[8] = I[13] / I[15];
234 values[9] = I[14] / I[15];
236 if (flg_sxsynormalization_)
241 values[12] = II[1] / (II3_2);
242 values[13] = a * II[2] / (II3_3);
248 void vpMomentCInvariant::calcSxSy(
double &sx,
double &sy)
const
250 sx = (c[2] * c[3] + s[2] * s[3]) / K;
251 sy = (s[2] * c[3] - c[2] * s[3]) / K;
259 void vpMomentCInvariant::calcSxSyNormalized(
double &sx,
double &sy)
const
261 sx = (cn[2] * cn[3] + sn[2] * sn[3]) / In1;
262 sy = (sn[2] * cn[3] - cn[2] * sn[3]) / In1;
278 for (
unsigned int i = 1; i < I.size(); ++i) {
280 os <<
"I[" << i <<
"]=" << I[i] << std::endl;
290 for (
unsigned int i = 0; i < c.
values.size(); i++) {
291 os << c.
values[i] <<
"," << std::endl;
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
error that can be emitted by ViSP classes.
@ notInitialized
Used to indicate that a parameter is not initialized.
vpMomentCInvariant(bool flg_sxsynormalization=false)
void printI(unsigned int index)
void printInvariants(std::ostream &os) const
This class defines the double-indexed centered moment descriptor .
double get(unsigned int i, unsigned int j) const
const vpMoment & get(const char *type, bool &found) const
const std::vector< double > & get() const
vpObjectType getType() const
std::vector< double > values
const vpMomentObject & getObject() const
vpMomentDatabase & getMoments() const