34 #include <visp3/core/vpConfig.h>
35 #include <visp3/blob/vpDot2.h>
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
54 void computeTopRightWithMoment(
const int &u_p,
const int &v_p,
float &dMuv,
float &dMu2,
float &dMv2)
56 float half_u_p =
static_cast<float>(0.5 * u_p);
57 dMuv =
static_cast<float>((v_p * v_p * (0.25 + half_u_p)) + (v_p * ((1. / 3.) + half_u_p)) + ((1. / 6.) * u_p) + 0.125);
58 dMu2 =
static_cast<float>(((-1. / 3.) * u_p * ((u_p * u_p) + (1.5 * u_p) + 1.)) - (1. / 12.0));
59 dMv2 =
static_cast<float>(((1. / 3.) * v_p * ((v_p * v_p) + (1.5 * v_p) + 1.)) + (1. / 12.0));
74 void computeTopLeftWithMoment(
const int &u_p,
const int &v_p,
float &dMuv,
float &dMu2,
float &dMv2)
76 float half_u_p =
static_cast<float>(0.5 * u_p);
77 dMuv =
static_cast<float>((((v_p * v_p * (0.25 - half_u_p)) + (v_p * ((1. / 3.) - half_u_p))) - ((1. / 6.) * u_p)) + 0.125);
78 dMu2 =
static_cast<float>(((-1. / 3.) * u_p * (((u_p * u_p) - (1.5 * u_p)) + 1.)) - (1. / 12.0));
79 dMv2 =
static_cast<float>(((-1. / 3.) * v_p * ((v_p * v_p) + (1.5 * v_p) + 1.)) - (1. / 12.0));
94 void computeDownRightWithMoment(
const int &u_p,
const int &v_p,
float &dMuv,
float &dMu2,
float &dMv2)
96 float half_u_p =
static_cast<float>(0.5 * u_p);
97 dMuv =
static_cast<float>(((v_p * v_p * (0.25 + half_u_p)) - (v_p * ((1. / 3.) + half_u_p))) + ((1. / 6.) * u_p) + 0.125);
98 dMu2 =
static_cast<float>(((1. / 3.) * u_p * ((u_p * u_p) + (1.5 * u_p) + 1.)) + (1. / 12.0));
99 dMv2 =
static_cast<float>(((1. / 3.) * v_p * (((v_p * v_p) - (1.5 * v_p)) + 1.)) - (1. / 12.0));
114 void computeDownLeftWithMoment(
const int &u_p,
const int &v_p,
float &dMuv,
float &dMu2,
float &dMv2)
116 float half_u_p =
static_cast<float>(0.5 * u_p);
117 dMuv =
static_cast<float>((((v_p * v_p * (0.25 - half_u_p)) - (v_p * ((1. / 3.) - half_u_p))) - ((1. / 6.) * u_p)) + 0.125);
118 dMu2 =
static_cast<float>(((1. / 3.) * u_p * (((u_p * u_p) - (1.5 * u_p)) + 1.)) - (1. / 12.0));
119 dMv2 =
static_cast<float>(((-1. / 3.) * v_p * (((v_p * v_p) - (1.5 * v_p)) + 1.)) - (1. / 12.0));
139 void vpDot2::getFreemanChain(std::list<unsigned int> &freeman_chain) const { freeman_chain = m_direction_list; }
159 bool vpDot2::computeFreemanChainElement(
const vpImage<unsigned char> &I,
const unsigned int &u,
const unsigned int &v,
160 unsigned int &element)
162 if (hasGoodLevel(I, u, v)) {
163 unsigned int v_u = u;
164 unsigned int v_v = v;
165 const unsigned int val_1 = 1;
166 const unsigned int val_2 = 2;
167 const unsigned int val_3 = 3;
168 const unsigned int val_4 = 4;
169 const unsigned int val_5 = 5;
170 const unsigned int val_6 = 6;
171 const unsigned int val_7 = 7;
172 const unsigned int val_8 = 8;
174 updateFreemanPosition(v_u, v_v, (element + val_2) % val_8);
175 if (hasGoodLevel(I, v_u, v_v)) {
176 element = (element + val_2) % val_8;
179 unsigned int v_u1 = u;
180 unsigned int v_v1 = v;
181 updateFreemanPosition(v_u1, v_v1, (element + val_1) % val_8);
183 if (hasGoodLevel(I, v_u1, v_v1)) {
184 element = (element + val_1) % val_8;
187 unsigned int v_u2 = u;
188 unsigned int v_v2 = v;
189 updateFreemanPosition(v_u2, v_v2, element);
191 if (hasGoodLevel(I, v_u2, v_v2)) {
195 unsigned int v_u3 = u;
196 unsigned int v_v3 = v;
197 updateFreemanPosition(v_u3, v_v3, (element + val_7) % val_8);
199 if (hasGoodLevel(I, v_u3, v_v3)) {
200 element = (element + val_7) % val_8;
203 unsigned int v_u4 = u;
204 unsigned int v_v4 = v;
205 updateFreemanPosition(v_u4, v_v4, (element + val_6) % val_8);
207 if (hasGoodLevel(I, v_u4, v_v4)) {
208 element = (element + val_6) % val_8;
211 unsigned int v_u5 = u;
212 unsigned int v_v5 = v;
213 updateFreemanPosition(v_u5, v_v5, (element + val_5) % val_8);
215 if (hasGoodLevel(I, v_u5, v_v5)) {
216 element = (element + val_5) % val_8;
219 unsigned int v_u6 = u;
220 unsigned int v_v6 = v;
221 updateFreemanPosition(v_u6, v_v6, (element + val_4) % val_8);
223 if (hasGoodLevel(I, v_u6, v_v6)) {
224 element = (element + val_4) % val_8;
227 unsigned int v_u7 = u;
228 unsigned int v_v7 = v;
229 updateFreemanPosition(v_u7, v_v7, (element + val_3) % val_8);
231 if (hasGoodLevel(I, v_u7, v_v7)) {
232 element = (element + val_3) % val_8;
284 void vpDot2::computeFreemanParameters(
const int &u_p,
const int &v_p,
unsigned int &element,
int &du,
int &dv,
285 float &dS,
float &dMu,
float &dMv,
float &dMuv,
float &dMu2,
float &dMv2)
296 const unsigned int go_right = 0;
297 const unsigned int go_right_top = 1;
298 const unsigned int go_top = 2;
299 const unsigned int go_top_left = 3;
300 const unsigned int go_left = 4;
301 const unsigned int go_left_down = 5;
302 const unsigned int go_down = 6;
303 const unsigned int go_down_right = 7;
309 const unsigned int val_2 = 2;
313 dS =
static_cast<float>(v_p);
315 dMv =
static_cast<float>(0.5 * v_p * v_p);
316 if (m_compute_moment) {
317 dMuv =
static_cast<float>(0.25 * v_p * v_p * ((val_2 * u_p) + 1));
319 dMv2 =
static_cast<float>((1.0 / 3.) * v_p * v_p * v_p);
326 dS =
static_cast<float>(v_p + 0.5);
327 dMu = -
static_cast<float>((0.5 * u_p * (u_p + 1)) + (1.0 / 6.0));
328 dMv =
static_cast<float>((0.5 * v_p * (v_p + 1)) + (1.0 / 6.0));
329 if (m_compute_moment) {
330 computeTopRightWithMoment(u_p, v_p, dMuv, dMu2, dMv2);
337 dMu =
static_cast<float>(-0.5 * u_p * u_p);
339 if (m_compute_moment) {
341 dMu2 =
static_cast<float>((-1.0 / 3.) * u_p * u_p * u_p);
349 dS =
static_cast<float>(-v_p - 0.5);
350 dMu = -
static_cast<float>((0.5 * u_p * (u_p - 1)) + (1.0 / 6.0));
351 dMv = -
static_cast<float>((0.5 * v_p * (v_p + 1)) + (1.0 / 6.0));
352 if (m_compute_moment) {
353 computeTopLeftWithMoment(u_p, v_p, dMuv, dMu2, dMv2);
359 dS =
static_cast<float>(-v_p);
360 dMv =
static_cast<float>(-0.5 * v_p * v_p);
362 if (m_compute_moment) {
363 dMuv =
static_cast<float>(-0.25 * v_p * v_p * ((val_2 * u_p) - 1));
365 dMv2 =
static_cast<float>((-1.0 / 3.) * v_p * v_p * v_p);
372 dS =
static_cast<float>(-v_p + 0.5);
373 dMu =
static_cast<float>((0.5 * u_p * (u_p - 1)) + (1.0 / 6.0));
374 dMv =
static_cast<float>(-((0.5 * v_p * (v_p - 1)) + (1.0 / 6.0)));
375 if (m_compute_moment) {
376 computeDownLeftWithMoment(u_p, v_p, dMuv, dMu2, dMv2);
383 dMu =
static_cast<float>(0.5 * u_p * u_p);
385 if (m_compute_moment) {
387 dMu2 =
static_cast<float>((1.0 / 3.) * u_p * u_p * u_p);
395 dS =
static_cast<float>(v_p - 0.5);
396 dMu =
static_cast<float>((0.5 * u_p * (u_p + 1)) + (1.0 / 6.0));
397 dMv =
static_cast<float>((0.5 * v_p * (v_p - 1)) + (1.0 / 6.0));
398 if (m_compute_moment) {
399 computeDownRightWithMoment(u_p, v_p, dMuv, dMu2, dMv2);
404 std::cout <<
"to complete the default" << std::endl;
421 void vpDot2::updateFreemanPosition(
unsigned int &u,
unsigned int &v,
const unsigned int &dir)
432 const unsigned int go_right = 0;
433 const unsigned int go_right_top = 1;
434 const unsigned int go_top = 2;
435 const unsigned int go_top_left = 3;
436 const unsigned int go_left = 4;
437 const unsigned int go_left_down = 5;
438 const unsigned int go_down = 6;
439 const unsigned int go_down_right = 7;
470 std::cout <<
"In vpDot2::updateFreemanPosition dir not identified" << std::endl;