49 #include <visp3/core/vpTrackingException.h>
50 #include <visp3/me/vpMe.h>
51 #include <visp3/me/vpMeSite.h>
53 #ifndef DOXYGEN_SHOULD_SKIP_THIS
54 static bool horsImage(
int i,
int j,
int half,
int rows,
int cols)
58 int half_1 = half + 1;
59 int half_3 = half + 3;
62 return ((0 < (half_1 - i)) || ((i - rows + half_3) > 0) || (0 < (half_1 - j)) || ((j - cols + half_3) > 0));
90 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
96 : 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),
97 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
98 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
106 : 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),
107 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
108 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
123 : 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),
124 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
125 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
138 selectDisplay =
NONE;
155 selectDisplay =
NONE;
169 void vpMeSite::init(
double ip,
double jp,
double alphap,
double convltp,
int sign)
171 selectDisplay =
NONE;
199 selectDisplay = m.selectDisplay;
202 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
221 unsigned int range_ =
static_cast<unsigned int>(range);
228 double salpha = sin(
alpha);
229 double calpha = cos(
alpha);
233 for (
int k = -range; k <= range; k++) {
234 double ii = (
ifloat + k * salpha);
235 double jj = (
jfloat + k * calpha);
250 list_query_pixels[n] = pel;
254 return (list_query_pixels);
257 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
272 double salpha = sin(
alpha);
273 double calpha = cos(
alpha);
286 if (I[i1][j1] > I[i2][j2])
297 int height_ =
static_cast<int>(I.
getHeight());
298 int width_ =
static_cast<int>(I.
getWidth());
302 half = (
static_cast<int>(msize) - 1) >> 1;
304 if (horsImage(
i,
j, half + me->
getStrip(), height_, width_)) {
310 double theta =
alpha + M_PI / 2;
321 if (abs(thetadeg) == 180) {
325 unsigned int index_mask = (
unsigned int)(thetadeg / (
double)me->
getAngleStep());
327 unsigned int i_ =
static_cast<unsigned int>(
i);
328 unsigned int j_ =
static_cast<unsigned int>(
j);
329 unsigned int half_ =
static_cast<unsigned int>(half);
331 unsigned int ihalf = i_ - half_;
332 unsigned int jhalf = j_ - half_;
334 for (
unsigned int a = 0; a < msize; a++) {
335 unsigned int ihalfa = ihalf + a;
336 for (
unsigned int b = 0; b < msize; b++) {
339 I(ihalfa, jhalf + b);
484 double max_convolution = 0;
486 double contraste = 0;
493 unsigned int range = me->
getRange();
499 double contraste_max = 1 + me->
getMu2();
500 double contraste_min = 1 - me->
getMu1();
503 double *likelihood =
new double[2 * range + 1];
514 for (
unsigned int n = 0; n < 2 * range + 1; n++) {
516 double convolution_ = list_query_pixels[n].
convolution(I, me);
521 if (test_contraste) {
522 likelihood[n] = fabs(convolution_ +
convlt);
523 if (likelihood[n] > threshold) {
524 contraste = convolution_ /
convlt;
525 if ((contraste > contraste_min) && (contraste < contraste_max) && fabs(1 - contraste) < diff) {
526 diff = fabs(1 - contraste);
527 max_convolution = convolution_;
537 likelihood[n] = fabs(2 * convolution_);
538 if (likelihood[n] > max && likelihood[n] > threshold) {
539 max_convolution = convolution_;
556 ip.
set_i(list_query_pixels[max_rank].
i);
557 ip.
set_j(list_query_pixels[max_rank].
j);
561 *
this = list_query_pixels[max_rank];
568 delete[] list_query_pixels;
573 ip.
set_i(list_query_pixels[0].
i);
574 ip.
set_j(list_query_pixels[0].
j);
579 if (std::fabs(contraste) > std::numeric_limits<double>::epsilon())
584 delete[] list_query_pixels;
593 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
594 return (os <<
"Alpha: " << vpMeS.
alpha <<
" Convolution: " << vpMeS.
convlt <<
" Flag: " << vpMeS.
suppress
595 <<
" Weight: " << vpMeS.
weight);
597 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.
@ CONSTRAST
Point removed due to a contrast problem.
@ TOO_NEAR
Point removed because too near image borders.
@ THRESHOLD
Point removed due to a threshold 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)
void track(const vpImage< unsigned char > &im, const vpMe *me, bool test_contraste=true)
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)
unsigned int getAngleStep() const
double getThreshold() const
unsigned int getMaskSize() const
vpMatrix * getMask() const
unsigned int getRange() const