44 #include <visp3/core/vpTrackingException.h>
45 #include <visp3/me/vpMe.h>
46 #include <visp3/me/vpMeSite.h>
48 #ifndef DOXYGEN_SHOULD_SKIP_THIS
49 static bool horsImage(
int i,
int j,
int half,
int rows,
int cols)
53 int half_1 = half + 1;
54 int half_3 = half + 3;
57 return ((0 < (half_1 - i)) || ((i - rows + half_3) > 0) || (0 < (half_1 - j)) || ((j - cols + half_3) > 0));
85 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
91 : i(0), j(0), i_1(0), j_1(0), ifloat(0), jfloat(0), v(0), mask_sign(1), alpha(0.), convlt(0.), normGradient(0),
92 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
93 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
100 : i(0), j(0), i_1(0), j_1(0), ifloat(0), jfloat(0), v(0), mask_sign(1), alpha(0.), convlt(0.), normGradient(0),
101 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
102 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
117 : i(0), j(0), i_1(0), j_1(0), ifloat(0), jfloat(0), v(0), mask_sign(1), alpha(0.), convlt(0.), normGradient(0),
118 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
119 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
132 selectDisplay =
NONE;
149 selectDisplay =
NONE;
163 void vpMeSite::init(
double ip,
double jp,
double alphap,
double convltp,
int sign)
165 selectDisplay =
NONE;
193 selectDisplay = m.selectDisplay;
196 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
215 unsigned int range_ =
static_cast<unsigned int>(range);
222 double salpha = sin(
alpha);
223 double calpha = cos(
alpha);
227 for (
int k = -range; k <= range; k++) {
228 double ii = (
ifloat + k * salpha);
229 double jj = (
jfloat + k * calpha);
244 list_query_pixels[n] = pel;
248 return (list_query_pixels);
251 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
266 double salpha = sin(
alpha);
267 double calpha = cos(
alpha);
280 if (I[i1][j1] > I[i2][j2])
291 int height_ =
static_cast<int>(I.
getHeight());
292 int width_ =
static_cast<int>(I.
getWidth());
296 half = (
static_cast<int>(msize) - 1) >> 1;
298 if (horsImage(
i,
j, half + me->
getStrip(), height_, width_)) {
305 double theta =
alpha + M_PI / 2;
316 if (abs(thetadeg) == 180) {
320 unsigned int index_mask = (
unsigned int)(thetadeg / (
double)me->
getAngleStep());
322 unsigned int i_ =
static_cast<unsigned int>(
i);
323 unsigned int j_ =
static_cast<unsigned int>(
j);
324 unsigned int half_ =
static_cast<unsigned int>(half);
326 unsigned int ihalf = i_ - half_;
327 unsigned int jhalf = j_ - half_;
329 for (
unsigned int a = 0; a < msize; a++) {
330 unsigned int ihalfa = ihalf + a;
331 for (
unsigned int b = 0; b < msize; b++) {
334 I(ihalfa, jhalf + b);
479 double max_convolution = 0;
488 unsigned int range = me->
getRange();
494 double contrast_max = 1 + me->
getMu2();
495 double contrast_min = 1 - me->
getMu1();
498 double *likelihood =
new double[2 * range + 1];
509 for (
unsigned int n = 0; n < 2 * range + 1; n++) {
511 double convolution_ = list_query_pixels[n].
convolution(I, me);
517 likelihood[n] = fabs(convolution_ +
convlt);
518 if (likelihood[n] > threshold) {
519 contrast = convolution_ /
convlt;
520 if ((contrast > contrast_min) && (contrast < contrast_max) && fabs(1 - contrast) < diff) {
521 diff = fabs(1 - contrast);
522 max_convolution = convolution_;
532 likelihood[n] = fabs(2 * convolution_);
533 if (likelihood[n] > max && likelihood[n] > threshold) {
534 max_convolution = convolution_;
551 ip.
set_i(list_query_pixels[max_rank].
i);
552 ip.
set_j(list_query_pixels[max_rank].
j);
556 *
this = list_query_pixels[max_rank];
563 delete [] list_query_pixels;
564 delete [] likelihood;
569 ip.
set_i(list_query_pixels[0].
i);
570 ip.
set_j(list_query_pixels[0].
j);
575 if (std::fabs(contrast) > std::numeric_limits<double>::epsilon())
580 delete [] list_query_pixels;
581 delete [] likelihood;
589 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
590 return (os <<
"Alpha: " << vpMeS.
alpha <<
" Convolution: " << vpMeS.
convlt <<
" Flag: " << vpMeS.
suppress
591 <<
" Weight: " << vpMeS.
weight);
593 return (os <<
"Alpha: " << vpMeS.
alpha <<
" Convolution: " << vpMeS.
convlt <<
" Weight: " << vpMeS.
weight);
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
static const vpColor cyan
static const vpColor blue
static const vpColor purple
static const vpColor yellow
static const vpColor green
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
unsigned int getHeight() const
static double sqr(double x)
static int round(double x)
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'....
vpMeSiteState
Moving-edge site state.
@ TOO_NEAR
Point removed because too near image borders.
@ THRESHOLD
Point removed due to a threshold problem.
@ CONTRAST
Point removed due to a contrast problem.
@ M_ESTIMATOR
Point removed during virtual visual-servoing because considered as an outlier.
@ NO_SUPPRESSION
Point used by the tracker.
void setDisplay(vpMeSiteDisplayType select)
int operator!=(const vpMeSite &m)
void display(const vpImage< unsigned char > &I)
double convolution(const vpImage< unsigned char > &ima, const vpMe *me)
vpMeSite & operator=(const vpMeSite &m)
vp_deprecated void getSign(const vpImage< unsigned char > &I, const int range)
vpMeSite * getQueryList(const vpImage< unsigned char > &I, const int range)
void track(const vpImage< unsigned char > &im, const vpMe *me, bool test_contrast=true)
unsigned int getAngleStep() const
double getThreshold() const
unsigned int getMaskSize() const
vpMatrix * getMask() const
unsigned int getRange() const