46 #include <visp3/core/vpColVector.h> 47 #include <visp3/core/vpMath.h> 48 #include <visp3/me/vpMe.h> 49 #ifndef DOXYGEN_SHOULD_SKIP_THIS 62 template <
class Type>
inline void permute(Type &a, Type &b)
69 static droite droite_cartesienne(point P, point Q)
75 PQ.c = Q.y * P.x - Q.x * P.y;
80 static point point_intersection(droite D1, droite D2)
85 det = (D1.a * D2.b - D2.a * D1.b);
86 I.x = (D2.c * D1.b - D1.c * D2.b) / det;
87 I.y = (D1.c * D2.a - D2.c * D1.a) / det;
92 static void recale(point &P,
double Xmin,
double Ymin,
double Xmax,
double Ymax)
105 static void permute(point &A, point &B)
118 static bool clipping(point A, point B,
double Xmin,
double Ymin,
double Xmax,
double Ymax, point &Ac,
142 AB = droite_cartesienne(A, B);
148 for (n = 0; n < 2; n++) {
163 if ((code_P[0] | code_P[1]) == 0000)
178 if ((code_P[0] & code_P[1]) != 0000)
187 if (code_P[0] != 0000) {
189 for (i = 0, bit_i = 1; !(code_P[0] & bit_i); i++, bit_i <<= 1) {
194 for (i = 0, bit_i = 1; !(code_P[1] & bit_i); i++, bit_i <<= 1) {
199 P[n] = point_intersection(AB, D[i]);
204 recale(P[n], Xmin, Ymin, Xmax, Ymax);
211 static double S_relative(point P, point Q,
double Xmin,
double Ymin,
double Xmax,
double Ymax)
217 recale(P, Xmin, Ymin, Xmax, Ymax);
218 recale(Q, Xmin, Ymin, Xmax, Ymax);
221 if ((std::fabs(P.x - Xmin) <=
222 vpMath::maximum(std::fabs(P.x), std::fabs(Xmin)) * std::numeric_limits<double>::epsilon()) &&
223 (std::fabs(Q.x - Xmax) <=
224 vpMath::maximum(std::fabs(Q.x), std::fabs(Xmax)) * std::numeric_limits<double>::epsilon()))
225 return (fabs(Ymax + Ymin - P.y - Q.y));
229 if (((std::fabs(P.y - Ymin) <=
230 vpMath::maximum(std::fabs(P.y), std::fabs(Ymin)) * std::numeric_limits<double>::epsilon()) &&
231 (std::fabs(Q.y - Ymax) <=
232 vpMath::maximum(std::fabs(Q.y), std::fabs(Ymax)) * std::numeric_limits<double>::epsilon())) ||
233 ((std::fabs(Q.y - Ymin) <=
234 vpMath::maximum(std::fabs(Q.y), std::fabs(Ymin)) * std::numeric_limits<double>::epsilon()) &&
235 (std::fabs(P.y - Ymax) <=
236 vpMath::maximum(std::fabs(P.y), std::fabs(Ymax)) * std::numeric_limits<double>::epsilon())))
237 return (fabs(Xmax + Xmin - P.x - Q.x));
240 if (std::fabs(P.x - Xmin) <=
241 vpMath::maximum(std::fabs(P.x), std::fabs(Xmin)) * std::numeric_limits<double>::epsilon() &&
242 std::fabs(Q.y - Ymax) <=
243 vpMath::maximum(std::fabs(Q.y), std::fabs(Ymax)) * std::numeric_limits<double>::epsilon())
244 return (1 - (Ymax - P.y) * (Q.x - Xmin));
246 if (std::fabs(P.x - Xmin) <=
247 vpMath::maximum(std::fabs(P.x), std::fabs(Xmin)) * std::numeric_limits<double>::epsilon() &&
248 std::fabs(Q.y - Ymin) <=
249 vpMath::maximum(std::fabs(Q.y), std::fabs(Ymin)) * std::numeric_limits<double>::epsilon())
250 return (1 - (P.y - Ymin) * (Q.x - Xmin));
252 if (std::fabs(P.y - Ymin) <=
253 vpMath::maximum(std::fabs(P.y), std::fabs(Ymin)) * std::numeric_limits<double>::epsilon() &&
254 std::fabs(Q.x - Xmax) <=
255 vpMath::maximum(std::fabs(Q.x), std::fabs(Xmax)) * std::numeric_limits<double>::epsilon())
256 return (1 - (Xmax - P.x) * (Q.y - Ymin));
258 if (std::fabs(P.y - Ymax) <=
259 vpMath::maximum(std::fabs(P.y), std::fabs(Ymax)) * std::numeric_limits<double>::epsilon() &&
260 std::fabs(Q.x - Xmax) <=
261 vpMath::maximum(std::fabs(Q.x), std::fabs(Xmax)) * std::numeric_limits<double>::epsilon())
262 return (1 - (Xmax - P.x) * (Ymax - Q.y));
264 printf(
"utils_ecm: ERREUR dans S_relative (%f,%f) (%f,%f) %f %f %f %f\n", P.x, P.y, Q.x, Q.y, Xmin, Ymin, Xmax, Ymax);
274 unsigned int i_theta,
277 moitie = ((double)n) / 2.0;
282 unsigned int nb_theta = angle.
getRows();
284 for (i_theta = 0; i_theta < nb_theta; i_theta++) {
285 double theta = M_PI / 180 * angle[i_theta];
287 double cos_theta = cos(theta);
288 double sin_theta = sin(theta);
293 if (std::fabs(angle[i_theta] - 90) <=
vpMath::maximum(std::fabs(angle[i_theta]), 90.) *
294 std::numeric_limits<double>::epsilon())
301 double tan_theta = sin_theta / cos_theta;
303 P1.y = tan_theta * (-(int)n);
305 Q1.y = tan_theta * n;
312 for (i = 0, Y = -moitie + 0.5; i < n; i++, Y++) {
313 for (j = 0, X = -moitie + 0.5; j < n; j++, X++) {
318 if (clipping(P1, Q1, X - 0.5, Y - 0.5, X + 0.5, Y + 0.5, P, Q)) {
320 v = S_relative(P, Q, X - 0.5, Y - 0.5, X + 0.5, Y + 0.5);
350 unsigned int angle_pas;
351 angle_pas = 180 / n_mask;
354 for (
unsigned int i = 0; k < n_mask; i += angle_pas)
357 calcul_masques(angle, mask_size, mask);
363 std::cout << std::endl;
364 std::cout <<
"Moving edges settings " << std::endl;
365 std::cout << std::endl;
366 std::cout <<
" Size of the convolution masks...." << mask_size <<
"x" << mask_size <<
" pixels" << std::endl;
367 std::cout <<
" Number of masks.................." << n_mask <<
" " << std::endl;
368 std::cout <<
" Query range +/- J................" << range <<
" pixels " << std::endl;
369 std::cout <<
" Likelihood test ratio............" << threshold << std::endl;
370 std::cout <<
" Contrast tolerance +/-..........." << mu1 * 100 <<
"% and " << mu2 * 100 <<
"% " << std::endl;
371 std::cout <<
" Sample step......................" << sample_step <<
" pixels" << std::endl;
372 std::cout <<
" Strip............................" << strip <<
" pixels " << std::endl;
373 std::cout <<
" Min_Samplestep..................." << min_samplestep <<
" pixels " << std::endl;
377 : threshold(1500), mu1(0.5), mu2(0.5), min_samplestep(4), anglestep(1), mask_sign(0), range(4), sample_step(10),
378 ntotal_sample(0), points_to_track(500), mask_size(5), n_mask(180), strip(2), mask(NULL)
419 #ifdef VISP_HAVE_CPP11_COMPATIBILITY 428 mu1 = std::move(me.mu1);
429 mu2 = std::move(me.mu2);
433 n_mask = std::move(me.n_mask);
435 range = std::move(me.range);
439 strip = std::move(me.strip);
Implementation of a matrix and operations on matrices.
void setMaskNumber(const unsigned int &a)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
static bool equal(double x, double y, double s=0.001)
int ntotal_sample
Distance between sampled points (in pixels)
static int round(const double x)
static Type maximum(const Type &a, const Type &b)
void setMaskSize(const unsigned int &a)
vpMe & operator=(const vpMe &me)
Copy operator.
unsigned int getRows() const
double min_samplestep
Contrast continuity parameter (right boundary)
Implementation of column vector and the associated operations.
double mu1
Likelihood ratio threshold.
double mu2
Contrast continuity parameter (left boundary)
static int() sign(double x)
double sample_step
Seek range - on both sides of the reference pixel.