34#ifndef DOXYGEN_SHOULD_SKIP_THIS
36#include <visp3/mbt/vpMbtMeEllipse.h>
38#include <visp3/core/vpDebug.h>
39#include <visp3/core/vpImagePoint.h>
40#include <visp3/core/vpRobust.h>
41#include <visp3/core/vpTrackingException.h>
42#include <visp3/me/vpMe.h>
67 bool display,
unsigned int length,
unsigned int thickness)
72 double offset =
static_cast<double>(std::floor(
static_cast<double>(SobelX.
getRows()) / 2.0));
73 int height =
static_cast<int>(I.getHeight());
74 int width =
static_cast<int>(I.getWidth());
76 double max_iImg =
height - 1.;
77 double max_jImg =
width - 1.;
82 for (std::list<vpMeSite>::iterator it = m_meList.begin(); it != m_meList.end(); ++it) {
83 double iSite = it->m_ifloat;
84 double jSite = it->m_jfloat;
90 vecSite[0] = cos(theta);
91 vecSite[1] = sin(theta);
97 for (
unsigned int i = 0;
i < SobelX.
getRows();
i++) {
98 double iImg = iSite + (
i - offset);
99 for (
unsigned int j = 0;
j < SobelX.
getCols();
j++) {
100 double jImg = jSite + (
j - offset);
112 gradientX += SobelX[
i][
j] * I(
static_cast<unsigned int>(iImg),
static_cast<unsigned int>(jImg));
116 for (
unsigned int i = 0;
i < SobelY.
getRows();
i++) {
117 double iImg = iSite + (
i - offset);
118 for (
unsigned int j = 0;
j < SobelY.
getCols();
j++) {
119 double jImg = jSite + (
j - offset);
131 gradientY += SobelY[
i][
j] * I(
static_cast<unsigned int>(iImg),
static_cast<unsigned int>(jImg));
135 double angle = atan2(gradientY, gradientX);
141 vecGrad[0] = cos(angle);
142 vecGrad[1] = sin(angle);
145 double angle1 = acos(vecSite * vecGrad);
146 double angle2 = acos(vecSite * (-vecGrad));
150 static_cast<int>(it->get_j() + length * sin(theta)),
vpColor::blue,
151 length >= 20 ? length / 5 : 4, length >= 20 ? length / 10 : 2, thickness);
152 if (angle1 < angle2) {
154 static_cast<int>(it->get_j() + length * sin(angle)),
vpColor::red,
155 length >= 20 ? length / 5 : 4, length >= 20 ? length / 10 : 2, thickness);
159 static_cast<int>(it->get_i() + length * cos(angle + M_PI)),
160 static_cast<int>(it->get_j() + length * sin(angle + M_PI)),
vpColor::red,
161 length >= 20 ? length / 5 : 4, length >= 20 ? length / 10 : 2, thickness);
165 sumErrorRad += std::min<double>(angle1, angle2);
173 double n11_p,
double n02_p,
bool doNotTrack,
vpImagePoint *pt1,
176 if (pt1 !=
nullptr && pt2 !=
nullptr) {
181 m_uc = center_p.
get_u();
182 m_vc = center_p.
get_v();
191 m_alpha1 = computeAngleOnEllipse(*pt1);
192 m_alpha2 = computeAngleOnEllipse(*pt2);
193 if ((m_alpha2 <= m_alpha1) || (std::fabs(m_alpha2 - m_alpha1) < m_arcEpsilon)) {
194 m_alpha2 += 2.0 * M_PI;
202 m_alpha2 = 2.0 * M_PI;
205 computePointOnEllipse(m_alpha1, ip);
210 m_iPc.set_uv(m_uc, m_vc);
212 sample(I, doNotTrack);
232 if (m_mask !=
nullptr) {
234 m_expectedDensity =
static_cast<unsigned int>(m_meList.size());
246 double n11_p,
double n02_p)
248 m_uc = center_p.
get_u();
249 m_vc = center_p.
get_v();
280 vpDERROR_TRACE(2,
"Tracking error: Moving edges not initialized");
284 unsigned int n = numberOfSignal();
285 if (
static_cast<double>(n) < 0.9 * m_expectedDensity) {
313 int nbrows =
static_cast<int>(I.getHeight());
314 int nbcols =
static_cast<int>(I.getWidth());
316 if (std::fabs(m_me->getSampleStep()) <= std::numeric_limits<double>::epsilon()) {
317 std::cout <<
"In vpMeEllipse::sample: ";
318 std::cout <<
"function called with sample step = 0, set to 10 dg";
319 m_me->setSampleStep(10.0);
323 m_expectedDensity =
static_cast<unsigned int>(floor((m_alpha2 - m_alpha1) / incr));
326 double ang = m_alpha1 + ((m_alpha2 - m_alpha1) -
static_cast<double>(m_expectedDensity) * incr) / 2.0;
328 for (
unsigned int i = 0;
i < m_expectedDensity;
i++) {
330 computePointOnEllipse(ang, iP);
334 double theta = computeTheta(iP);
340 const double marginRatio = m_me->getThresholdMarginRatio();
342 double contrastThreshold = fabs(convolution) * marginRatio;
344 m_meList.push_back(pix);
345 m_angleList.push_back(ang);
358void vpMbtMeEllipse::suppressPoints()
361 for (std::list<vpMeSite>::iterator it = m_meList.begin(); it != m_meList.end();) {
364 it = m_meList.erase(it);
unsigned int getCols() const
unsigned int getRows() const
Implementation of column vector and the associated operations.
static const vpColor blue
static void displayArrow(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)
error that can be emitted by ViSP classes.
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.
static double rad(double deg)
static int round(double x)
Implementation of a matrix and operations on matrices.
void track(const vpImage< unsigned char > &I)
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'....
@ NO_SUPPRESSION
Point successfully tracked.
void setDisplay(vpMeSiteDisplayType select)
double convolution(const vpImage< unsigned char > &ima, const vpMe *me)
void setContrastThreshold(const double &thresh, const vpMe &me)
void setState(const vpMeSiteState &flag)
void initTracking(const vpImage< unsigned char > &I)
Error that can be emitted by the vpTracker class and its derivatives.
@ initializationError
Tracker initialization error.