42#include <visp3/core/vpTrackingException.h>
43#include <visp3/me/vpMe.h>
44#include <visp3/me/vpMeSite.h>
46#ifndef DOXYGEN_SHOULD_SKIP_THIS
47static bool horsImage(
int i,
int j,
int half,
int rows,
int cols)
51 int half_1 = half + 1;
52 int half_3 = half + 3;
55 return ((0 < (half_1 - i)) || ((i - rows + half_3) > 0) || (0 < (half_1 - j)) || ((j - cols + half_3) > 0));
80#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
86 : i(0), j(0), ifloat(0), jfloat(0), mask_sign(1), alpha(0.), convlt(0.), normGradient(0),
87 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
88#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
95 : i(0), j(0), ifloat(0), jfloat(0), mask_sign(1), alpha(0.), convlt(0.), normGradient(0),
96 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
97#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
109 : i(0), j(0), ifloat(0), jfloat(0), mask_sign(1), alpha(0.), convlt(0.), normGradient(0),
110 weight(1), selectDisplay(NONE), state(NO_SUPPRESSION)
111#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
124 selectDisplay =
NONE;
137 selectDisplay =
NONE;
148void vpMeSite::init(
double ip,
double jp,
double alphap,
double convltp,
int sign)
150 selectDisplay =
NONE;
171 selectDisplay = m.selectDisplay;
174#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
183 unsigned int range_ =
static_cast<unsigned int>(range);
190 double salpha = sin(
alpha);
191 double calpha = cos(
alpha);
195 for (
int k = -range; k <= range; k++) {
196 double ii = (
ifloat + k * salpha);
197 double jj = (
jfloat + k * calpha);
212 list_query_pixels[n] = pel;
216 return (list_query_pixels);
219#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
232 double salpha = sin(
alpha);
233 double calpha = cos(
alpha);
245 if (I[i1][j1] > I[i2][j2])
256 int height_ =
static_cast<int>(I.
getHeight());
257 int width_ =
static_cast<int>(I.
getWidth());
261 half = (
static_cast<int>(msize) - 1) >> 1;
263 if (horsImage(
i,
j, half + me->
getStrip(), height_, width_)) {
270 double theta =
alpha + M_PI / 2;
281 if (abs(thetadeg) == 180) {
285 unsigned int index_mask = (
unsigned int)(thetadeg / (
double)me->
getAngleStep());
287 unsigned int i_ =
static_cast<unsigned int>(
i);
288 unsigned int j_ =
static_cast<unsigned int>(
j);
289 unsigned int half_ =
static_cast<unsigned int>(half);
291 unsigned int ihalf = i_ - half_;
292 unsigned int jhalf = j_ - half_;
294 for (
unsigned int a = 0; a < msize; a++) {
295 unsigned int ihalfa = ihalf + a;
296 for (
unsigned int b = 0; b < msize; b++) {
308 double max_convolution = 0;
314 unsigned int range = me->
getRange();
318 double contrast_max = 1 + me->
getMu2();
319 double contrast_min = 1 - me->
getMu1();
322 double *likelihood =
new double[2 * range + 1];
330 threshold = me->
getThreshold() / (100.0 * n_d * trunc(n_d / 2.0));
335 for (
unsigned int n = 0; n < 2 * range + 1; n++) {
337 double convolution_ = list_query_pixels[n].
convolution(I, me);
342 likelihood[n] = fabs(convolution_ +
convlt);
343 if (likelihood[n] > threshold) {
344 contrast = convolution_ /
convlt;
345 if ((contrast > contrast_min) && (contrast < contrast_max) && fabs(1 - contrast) < diff) {
346 diff = fabs(1 - contrast);
347 max_convolution = convolution_;
355 for (
unsigned int n = 0; n < 2 * range + 1; n++) {
357 double convolution_ = list_query_pixels[n].
convolution(I, me);
358 likelihood[n] = fabs(2 * convolution_);
359 if (likelihood[n] > max && likelihood[n] > threshold) {
360 max_convolution = convolution_;
371 ip.
set_i(list_query_pixels[max_rank].
i);
372 ip.
set_j(list_query_pixels[max_rank].
j);
376 *
this = list_query_pixels[max_rank];
382 delete[] list_query_pixels;
388 ip.
set_i(list_query_pixels[0].
i);
389 ip.
set_j(list_query_pixels[0].
j);
393 if (std::fabs(contrast) > std::numeric_limits<double>::epsilon())
398 delete[] list_query_pixels;
405VISP_EXPORT std::ostream &operator<<(std::ostream &os,
vpMeSite &vpMeS)
407#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
408 return (os <<
"Alpha: " << vpMeS.
alpha <<
" Convolution: " << vpMeS.
convlt <<
" Flag: " << vpMeS.
suppress
409 <<
" Weight: " << vpMeS.
weight);
411 return (os <<
"Alpha: " << vpMeS.
alpha <<
" Convolution: " << vpMeS.
convlt <<
" Weight: " << vpMeS.
weight);
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 ...
Definition of the vpImage class member functions.
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'....
int j
Coordinates along j of a site.
@ 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)
double weight
Uncertainty of point given as a probability between 0 and 1.
int operator!=(const vpMeSite &m)
void display(const vpImage< unsigned char > &I)
double ifloat
Floating coordinates along i of a site.
double convolution(const vpImage< unsigned char > &ima, const vpMe *me)
int i
Coordinate along i of a site.
vpMeSite & operator=(const vpMeSite &m)
vp_deprecated void getSign(const vpImage< unsigned char > &I, const int range)
double normGradient
Convolution of Site in previous image.
double alpha
Angle of tangent at site.
double jfloat
Floating coordinates along j of a site.
vpMeSite * getQueryList(const vpImage< unsigned char > &I, const int range)
double convlt
Convolution of Site in previous image.
void track(const vpImage< unsigned char > &im, const vpMe *me, bool test_likelihood=true)
vpLikelihoodThresholdType getLikelihoodThresholdType() const
unsigned int getAngleStep() const
vpMatrix * getMask() const
double getThreshold() const
unsigned int getMaskSize() const
unsigned int getRange() const
@ NORMALIZED_THRESHOLD
Easy-to-use normalized likelihood threshold corresponding to the minimal luminance contrast to consid...