Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
tutorial-pf-curve-fitting-all.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  */
30 
32 
33 // System includes
34 #include <algorithm>
35 #include <vector>
36 
37 // ViSP includes
38 #include <visp3/core/vpConfig.h>
39 #include <visp3/core/vpException.h>
40 #include <visp3/core/vpMouseButton.h>
41 #include <visp3/core/vpTime.h>
42 
43 #ifdef VISP_HAVE_DISPLAY
44 #include <visp3/gui/vpPlot.h>
45 #endif
46 
48 #include <visp3/core/vpParticleFilter.h>
50 
51 #include "vpTutoCommonData.h"
52 #include "vpTutoMeanSquareFitting.h"
53 #include "vpTutoParabolaModel.h"
54 #include "vpTutoSegmentation.h"
55 
56 #ifdef ENABLE_VISP_NAMESPACE
57 using namespace VISP_NAMESPACE_NAME;
58 #endif
59 
60 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && defined(VISP_HAVE_DISPLAY)
61 #ifndef DOXYGEN_SHOULD_SKIP_THIS
62 namespace tutorial
63 {
65 
72 double evaluate(const vpImagePoint &pt, const vpTutoParabolaModel &model)
73 {
74  double u = pt.get_u();
75  double v = pt.get_v();
76  double v_model = model.eval(u);
77  double error = v - v_model;
78  double squareError = error * error;
79  return squareError;
80 }
81 
92 double evaluate(const vpColVector &coeffs, const unsigned int &height, const unsigned int &width, const std::vector<vpImagePoint> &pts)
93 {
94  unsigned int nbPts = static_cast<unsigned int>(pts.size());
95  vpColVector residuals(nbPts);
96  vpColVector weights(nbPts, 1.);
97  vpTutoParabolaModel model(coeffs, height, width);
98  // Compute the residuals
99  for (unsigned int i = 0; i < nbPts; ++i) {
100  double squareError = evaluate(pts[i], model);
101  residuals[i] = squareError;
102  }
103  double meanSquareError = residuals.sum() / static_cast<double>(nbPts);
104  return std::sqrt(meanSquareError);
105 }
107 
109 
117 template<typename T>
118 void display(const vpColVector &coeffs, const vpImage<T> &I, const vpColor &color,
119  const unsigned int &vertPosLegend, const unsigned int &horPosLegend)
120 {
121 #if defined(VISP_HAVE_DISPLAY)
122  unsigned int width = I.getWidth();
123  vpTutoParabolaModel model(coeffs, I.getHeight(), I.getWidth());
124  for (unsigned int u = 0; u < width; ++u) {
125  unsigned int v = static_cast<unsigned int>(model.eval(u));
126  vpDisplay::displayPoint(I, v, u, color, 1);
127  vpDisplay::displayText(I, vertPosLegend, horPosLegend, "Particle Filter model", color);
128  }
129 #else
130  (void)coeffs;
131  (void)I;
132  (void)color;
133  (void)vertPosLegend;
134  (void)horPosLegend;
135 #endif
136 }
138 
140 
147 std::vector<vpImagePoint> automaticInitialization(tutorial::vpTutoCommonData &data)
148 {
149  // Initialization-related variables
150  const unsigned int minNbPts = data.m_degree + 1;
151  const unsigned int nbPtsToUse = 10 * minNbPts;
152  std::vector<vpImagePoint> initPoints;
153 
154  // Perform HSV segmentation
155  tutorial::performSegmentationHSV(data);
156 
157  // Extracting the skeleton of the mask
158  std::vector<vpImagePoint> edgePoints = tutorial::extractSkeleton(data);
159  unsigned int nbEdgePoints = static_cast<unsigned int>(edgePoints.size());
160 
161  if (nbEdgePoints < nbPtsToUse) {
162  return edgePoints;
163  }
164 
165  // Uniformly extract init points
166  auto ptHasLowerU = [](const vpImagePoint &ptA, const vpImagePoint &ptB) {
167  return ptA.get_u() < ptB.get_u();
168  };
169  std::sort(edgePoints.begin(), edgePoints.end(), ptHasLowerU);
170 
171  unsigned int idStart, idStop;
172  if (nbEdgePoints > nbPtsToUse + 20) {
173  // Avoid extreme points in case it's noise
174  idStart = 10;
175  idStop = static_cast<unsigned int>(edgePoints.size()) - 10;
176  }
177  else {
178  // We need to take all the points because we don't have enough
179  idStart = 0;
180  idStop = static_cast<unsigned int>(edgePoints.size());
181  }
182 
183  // Sample uniformly the points starting from the left of the image to the right
184  unsigned int sizeWindow = idStop - idStart + 1;
185  unsigned int step = sizeWindow / (nbPtsToUse - 1);
186  for (unsigned int id = idStart; id <= idStop; id += step) {
187  initPoints.push_back(edgePoints[id]);
188  }
189  return initPoints;
190 }
191 
198 std::vector<vpImagePoint> manualInitialization(const tutorial::vpTutoCommonData &data)
199 {
200  // Interaction variables
201  const bool waitForClick = true;
202  vpImagePoint ipClick;
204 
205  // Display variables
206  const unsigned int sizeCross = 10;
207  const unsigned int thicknessCross = 2;
208  const vpColor colorCross = vpColor::red;
209 
210  // Initialization-related variables
211  const unsigned int minNbPts = data.m_degree + 1;
212  std::vector<vpImagePoint> initPoints;
213 
214  bool notEnoughPoints = true;
215  while (notEnoughPoints) {
216  // Initial display of the images
217  vpDisplay::display(data.m_I_orig);
218 
219  // Display the how-to
220  vpDisplay::displayText(data.m_I_orig, data.m_ipLegend, "Left click to add init point (min.: " + std::to_string(minNbPts) + "), right click to estimate the initial coefficients of the Particle Filter.", data.m_colorLegend);
221  vpDisplay::displayText(data.m_I_orig, data.m_ipLegend + data.m_legendOffset, "A middle click reinitialize the list of init points.", data.m_colorLegend);
222  vpDisplay::displayText(data.m_I_orig, data.m_ipLegend + data.m_legendOffset + data.m_legendOffset, "If not enough points have been selected, a right click has no effect.", data.m_colorLegend);
223 
224  // Display the already selected points
225  unsigned int nbInitPoints = static_cast<unsigned int>(initPoints.size());
226  for (unsigned int i = 0; i < nbInitPoints; ++i) {
227  vpDisplay::displayCross(data.m_I_orig, initPoints[i], sizeCross, colorCross, thicknessCross);
228  }
229 
230  // Update the display
231  vpDisplay::flush(data.m_I_orig);
232 
233  // Get the user input
234  vpDisplay::getClick(data.m_I_orig, ipClick, button, waitForClick);
235 
236  // Either add the clicked point to the list of initial points or stop the loop if enough points are available
237  switch (button) {
238  case vpMouseButton::vpMouseButtonType::button1:
239  initPoints.push_back(ipClick);
240  break;
241  case vpMouseButton::vpMouseButtonType::button2:
242  initPoints.clear();
243  break;
244  case vpMouseButton::vpMouseButtonType::button3:
245  (initPoints.size() >= minNbPts ? notEnoughPoints = false : notEnoughPoints = true);
246  break;
247  default:
248  break;
249  }
250  }
251 
252  return initPoints;
253 }
254 
263 vpColVector computeInitialGuess(tutorial::vpTutoCommonData &data)
264 {
265  // Vector that contains the init points
266  std::vector<vpImagePoint> initPoints;
267 
268 #ifdef VISP_HAVE_DISPLAY
269  // Interaction variables
270  const bool waitForClick = true;
271  vpImagePoint ipClick;
273 
274  // Display variables
275  const unsigned int sizeCross = 10;
276  const unsigned int thicknessCross = 2;
277  const vpColor colorCross = vpColor::red;
278 
279  bool automaticInit = false;
280 
281  // Initial display of the images
282  vpDisplay::display(data.m_I_orig);
283  vpDisplay::displayText(data.m_I_orig, data.m_ipLegend, "Left click to manually select the init points, right click to automatically initialize the PF", data.m_colorLegend);
284 
285  // Update the display
286  vpDisplay::flush(data.m_I_orig);
287 
288  // Get the user input
289  vpDisplay::getClick(data.m_I_orig, ipClick, button, waitForClick);
290 
291  // Either use the automatic initialization or the manual one depending on the user input
292  switch (button) {
293  case vpMouseButton::vpMouseButtonType::button1:
294  automaticInit = false;
295  break;
296  case vpMouseButton::vpMouseButtonType::button3:
297  automaticInit = true;
298  break;
299  default:
300  break;
301  }
302 
303  if (automaticInit) {
304  // Get automatically the init points from the segmented image
305  initPoints = tutorial::automaticInitialization(data);
306  }
307  else {
308  // Get manually the init points from the original image
309  initPoints = tutorial::manualInitialization(data);
310  }
311 
312 #else
313  // Get the init points from the segmented image
314  initPoints = tutorial::automaticInitialization(data);
315 #endif
316 
317  // Compute the coefficients of the parabola using Least-Mean-Square minimization.
318  tutorial::vpTutoMeanSquareFitting lmsFitter(data.m_degree, data.m_I_orig.getHeight(), data.m_I_orig.getWidth());
319  lmsFitter.fit(initPoints);
320  vpColVector X0 = lmsFitter.getCoeffs();
321  std::cout << "---[Initial fit]---" << std::endl;
322  std::cout << lmsFitter.getModel();
323  std::cout << "---[Initial fit]---" << std::endl;
324 
325  // Display info about the initialization
326  vpDisplay::display(data.m_I_orig);
327  vpDisplay::displayText(data.m_I_orig, data.m_ipLegend, "Here are the points selected for the initialization.", data.m_colorLegend);
328  size_t nbInitPoints = initPoints.size();
329  for (size_t i = 0; i < nbInitPoints; ++i) {
330  const vpImagePoint &ip = initPoints[i];
331  vpDisplay::displayCross(data.m_I_orig, ip, sizeCross, colorCross, thicknessCross);
332  }
333 
334  // Update display and wait for click
335  lmsFitter.display(data.m_I_orig, vpColor::red, static_cast<unsigned int>(data.m_ipLegend.get_v() + 2 * data.m_legendOffset.get_v()), static_cast<unsigned int>(data.m_ipLegend.get_u()));
336  vpDisplay::displayText(data.m_I_orig, data.m_ipLegend + data.m_legendOffset, "A click to continue.", data.m_colorLegend);
337  vpDisplay::flush(data.m_I_orig);
338  vpDisplay::getClick(data.m_I_orig, waitForClick);
339 
340  return X0;
341 }
343 
345 vpColVector fx(const vpColVector &coeffs, const double &/*dt*/)
346 {
347  vpColVector updatedCoeffs = coeffs; // We use a constant position model
348  return updatedCoeffs;
349 }
351 
353 class vpTutoAverageFunctor
354 {
355 public:
356  vpTutoAverageFunctor(const unsigned int &degree, const unsigned int &height, const unsigned int &width)
357  : m_degree(degree)
358  , m_height(height)
359  , m_width(width)
360  { }
361 
371  vpColVector averagePolynomials(const std::vector<vpColVector> &particles, const std::vector<double> &weights, const vpParticleFilter<std::vector<vpImagePoint>>::vpStateAddFunction &)
372  {
373  const unsigned int nbParticles = static_cast<unsigned int>(particles.size());
374  const double nbParticlesAsDOuble = static_cast<double>(nbParticles);
375  // Compute the sum of the weights to be able to determine the "importance" of a particle with regard to the whole set
376  const double sumWeight = std::accumulate(weights.begin(), weights.end(), 0.);
377 
378  // Defining the total number of control points we want to generate
379  const double nbPointsForAverage = 10. * nbParticlesAsDOuble;
380  std::vector<vpImagePoint> initPoints;
381 
382  // Creating control points by each particle
383  for (unsigned int i = 0; i < nbParticles; ++i) {
384  // The number of control points a particle can generate is proportional to the ratio of its weight w.r.t. the sum of the weights
385  double nbPoints = std::floor(weights[i] * nbPointsForAverage / sumWeight);
386  if (nbPoints > 1.) {
387  // The particle has a weight high enough to deserve more than one points
388  vpTutoParabolaModel curve(particles[i], m_height, m_width);
389  double widthAsDouble = static_cast<double>(m_width);
390  // Uniform sampling of the control points along the polynomial model
391  double step = widthAsDouble / (nbPoints - 1.);
392  for (double u = 0.; u < widthAsDouble; u += step) {
393  double v = curve.eval(u);
394  vpImagePoint pt(v, u);
395  initPoints.push_back(pt);
396  }
397  }
398  else if (nbPoints == 1.) {
399  // The weight of the particle make it have only one control point
400  // We sample it at the middle of the image
401  vpTutoParabolaModel curve(particles[i], m_height, m_width);
402  double u = static_cast<double>(m_width) / 2.;
403  double v = curve.eval(u);
404  vpImagePoint pt(v, u);
405  initPoints.push_back(pt);
406  }
407  }
408  // We use Least-Mean Square minimization to compute the polynomial model that best fits all the control points
409  vpTutoMeanSquareFitting lms(m_degree, m_height, m_width);
410  lms.fit(initPoints);
411  return lms.getCoeffs();
412  }
413 
414 private:
415  unsigned int m_degree;
416  unsigned int m_height;
417  unsigned int m_width;
418 };
420 
422 class vpTutoLikelihoodFunctor
423 {
424 public:
432  vpTutoLikelihoodFunctor(const double &stdev, const unsigned int &height, const unsigned int &width)
433  : m_height(height)
434  , m_width(width)
435  {
436  double sigmaDistanceSquared = stdev * stdev;
437  m_constantDenominator = 1. / std::sqrt(2. * M_PI * sigmaDistanceSquared);
438  m_constantExpDenominator = -1. / (2. * sigmaDistanceSquared);
439  }
440 
442 
454  double likelihood(const vpColVector &coeffs, const std::vector<vpImagePoint> &meas)
455  {
456  double likelihood = 0.;
457  unsigned int nbPoints = static_cast<unsigned int>(meas.size());
458 
459  // Generate a model from the coefficients stored in the particle state
460  vpTutoParabolaModel model(coeffs, m_height, m_width);
461 
462  // Compute the residual between each measurement point and its equivalent in the model
463  vpColVector residuals(nbPoints);
464  for (unsigned int i = 0; i < nbPoints; ++i) {
465  double squareError = tutorial::evaluate(meas[i], model);
466  residuals[i] = squareError;
467  }
468 
469  // Use Tukey M-estimator to be robust against outliers
470  vpRobust Mestimator;
471  vpColVector w(nbPoints, 1.);
472  Mestimator.MEstimator(vpRobust::TUKEY, residuals, w);
473  double sumError = w.hadamard(residuals).sum();
474 
475  // Compute the likelihood as a Gaussian function
476  likelihood = std::exp(m_constantExpDenominator * sumError / w.sum()) * m_constantDenominator;
477  likelihood = std::min(likelihood, 1.0); // Clamp to have likelihood <= 1.
478  likelihood = std::max(likelihood, 0.); // Clamp to have likelihood >= 0.
479  return likelihood;
480  }
482 private:
483  double m_constantDenominator;
484  double m_constantExpDenominator;
485  unsigned int m_height;
486  unsigned int m_width;
487 };
489 }
490 #endif
491 
492 int main(const int argc, const char *argv[])
493 {
494  tutorial::vpTutoCommonData data;
495  int returnCode = data.init(argc, argv);
496  if (returnCode != tutorial::vpTutoCommonData::SOFTWARE_CONTINUE) {
497  return returnCode;
498  }
499  tutorial::vpTutoMeanSquareFitting lmsFitter(data.m_degree, data.m_I_orig.getHeight(), data.m_I_orig.getWidth());
500  const unsigned int vertOffset = static_cast<unsigned int>(data.m_legendOffset.get_i());
501  const unsigned int horOffset = static_cast<unsigned int>(data.m_ipLegend.get_j());
502  const unsigned int legendLmsVert = data.m_I_orig.getHeight() - 3 * vertOffset;
503  const unsigned int legendLmsHor = horOffset;
504  const unsigned int legendPFVert = data.m_I_orig.getHeight() - 2 * vertOffset, legendPFHor = horOffset;
505 
506  // Initialize the attributes of the PF
508  vpColVector X0 = tutorial::computeInitialGuess(data);
510 
512  const double maxDistanceForLikelihood = data.m_pfMaxDistanceForLikelihood; // The maximum allowed distance between a particle and the measurement, leading to a likelihood equal to 0..
513  const double sigmaLikelihood = maxDistanceForLikelihood / 3.; // The standard deviation of likelihood function.
514  const unsigned int nbParticles = data.m_pfN; // Number of particles to use
515  std::vector<double> stdevsPF; // Standard deviation for each state component
516  for (unsigned int i = 0; i < data.m_degree + 1; ++i) {
517  double ampliMax = data.m_pfRatiosAmpliMax[i] * X0[i];
518  stdevsPF.push_back(ampliMax / 3.);
519  }
520  unsigned long seedPF; // Seed for the random generators of the PF
521  const float period = 33.3f; // 33.3ms i.e. 30Hz
522  if (data.m_pfSeed < 0) {
523  seedPF = static_cast<unsigned long>(vpTime::measureTimeMicros());
524  }
525  else {
526  seedPF = data.m_pfSeed;
527  }
528  const int nbThread = data.m_pfNbThreads;
530 
532  vpParticleFilter<std::vector<vpImagePoint>>::vpProcessFunction processFunc = tutorial::fx;
533  tutorial::vpTutoLikelihoodFunctor likelihoodFtor(sigmaLikelihood, data.m_I_orig.getHeight(), data.m_I_orig.getWidth());
534  using std::placeholders::_1;
535  using std::placeholders::_2;
536  vpParticleFilter<std::vector<vpImagePoint>>::vpLikelihoodFunction likelihoodFunc = std::bind(&tutorial::vpTutoLikelihoodFunctor::likelihood, &likelihoodFtor, _1, _2);
537  vpParticleFilter<std::vector<vpImagePoint>>::vpResamplingConditionFunction checkResamplingFunc = vpParticleFilter<std::vector<vpImagePoint>>::simpleResamplingCheck;
538  vpParticleFilter<std::vector<vpImagePoint>>::vpResamplingFunction resamplingFunc = vpParticleFilter<std::vector<vpImagePoint>>::simpleImportanceResampling;
539  tutorial::vpTutoAverageFunctor averageCpter(data.m_degree, data.m_I_orig.getHeight(), data.m_I_orig.getWidth());
540  using std::placeholders::_3;
541  vpParticleFilter<std::vector<vpImagePoint>>::vpFilterFunction meanFunc = std::bind(&tutorial::vpTutoAverageFunctor::averagePolynomials, &averageCpter, _1, _2, _3);
543 
545  // Initialize the PF
546  vpParticleFilter<std::vector<vpImagePoint>> filter(nbParticles, stdevsPF, seedPF, nbThread);
547  filter.init(X0, processFunc, likelihoodFunc, checkResamplingFunc, resamplingFunc, meanFunc);
549 
551 #ifdef VISP_HAVE_DISPLAY
552  unsigned int plotHeight = 350, plotWidth = 350;
553  int plotXpos = static_cast<int>(data.m_legendOffset.get_u());
554  int plotYpos = static_cast<int>(data.m_I_orig.getHeight() + 4. * data.m_legendOffset.get_v());
555  vpPlot plot(1, plotHeight, plotWidth, plotXpos, plotYpos, "Root mean-square error");
556  plot.initGraph(0, 2);
557  plot.setLegend(0, 0, "LMS estimator");
558  plot.setColor(0, 0, vpColor::gray);
559  plot.setLegend(0, 1, "PF estimator");
560  plot.setColor(0, 1, vpColor::red);
561 #endif
563 
564  bool run = true;
565  unsigned int nbIter = 0;
566  double meanDtLMS = 0., meanDtPF = 0.;
567  double meanRootMeanSquareErrorLMS = 0., meanRootMeanSquareErrorPF = 0.;
568  while (!data.m_grabber.end() && run) {
569  std::cout << "Iter " << nbIter << std::endl;
570  data.m_grabber.acquire(data.m_I_orig);
571 
572  tutorial::performSegmentationHSV(data);
573 
575  std::vector<vpImagePoint> edgePoints = tutorial::extractSkeleton(data);
576 
578  std::vector<vpImagePoint> noisyEdgePoints = tutorial::addSaltAndPepperNoise(edgePoints, data);
579 
580 #ifdef VISP_HAVE_DISPLAY
582  vpDisplay::display(data.m_I_orig);
583  vpDisplay::display(data.m_I_segmented);
584  vpDisplay::display(data.m_IskeletonNoisy);
585 #endif
586 
588  double tLms = vpTime::measureTimeMs();
589  lmsFitter.fit(noisyEdgePoints);
590  double dtLms = vpTime::measureTimeMs() - tLms;
591  double lmsRootMeanSquareError = lmsFitter.evaluate(edgePoints);
592  std::cout << " [Least-Mean Square method] " << std::endl;
593  std::cout << " Coeffs = [" << lmsFitter.getCoeffs().transpose() << " ]" << std::endl;
594  std::cout << " Root Mean Square Error = " << lmsRootMeanSquareError << " pixels" << std::endl;
595  std::cout << " Fitting duration = " << dtLms << " ms" << std::endl;
596  meanDtLMS += dtLms;
597  meanRootMeanSquareErrorLMS += lmsRootMeanSquareError;
598 
600  double tPF = vpTime::measureTimeMs();
602  filter.filter(noisyEdgePoints, period);
604  double dtPF = vpTime::measureTimeMs() - tPF;
605 
607  vpColVector Xest = filter.computeFilteredState();
609 
611  double pfError = tutorial::evaluate(Xest, data.m_I_orig.getHeight(), data.m_I_orig.getWidth(), edgePoints);
613  std::cout << " [Particle Filter method] " << std::endl;
614  std::cout << " Coeffs = [" << Xest.transpose() << " ]" << std::endl;
615  std::cout << " Root Mean Square Error = " << pfError << " pixels" << std::endl;
616  std::cout << " Fitting duration = " << dtPF << " ms" << std::endl;
617  meanDtPF += dtPF;
618  meanRootMeanSquareErrorPF += pfError;
619 
620 #ifdef VISP_HAVE_DISPLAY
621  // Update image overlay
622  lmsFitter.display<unsigned char>(data.m_IskeletonNoisy, vpColor::gray, legendLmsVert, legendLmsHor);
623  tutorial::display(Xest, data.m_IskeletonNoisy, vpColor::red, legendPFVert, legendPFHor);
624 
625  // Update plot
626  plot.plot(0, 0, nbIter, lmsRootMeanSquareError);
627  plot.plot(0, 1, nbIter, pfError);
628  // Display the images with overlayed info
629  data.displayLegend(data.m_I_orig);
630  vpDisplay::flush(data.m_I_orig);
631  vpDisplay::flush(data.m_I_segmented);
632  vpDisplay::flush(data.m_IskeletonNoisy);
633  run = data.manageClicks(data.m_I_orig, data.m_stepbystep);
634 #endif
635  ++nbIter;
636  }
637 
638  double iterAsDouble = static_cast<double>(nbIter);
639 
640  std::cout << std::endl << std::endl << "-----[Statistics summary]-----" << std::endl;
641 
642  std::cout << " [LMS method] " << std::endl;
643  std::cout << " Average Root Mean Square Error = " << meanRootMeanSquareErrorLMS / iterAsDouble << " pixels" << std::endl;
644  std::cout << " Average fitting duration = " << meanDtLMS / iterAsDouble << " ms" << std::endl;
645 
646  std::cout << " [Particle Filter method] " << std::endl;
647  std::cout << " Average Root Mean Square Error = " << meanRootMeanSquareErrorPF / iterAsDouble << " pixels" << std::endl;
648  std::cout << " Average fitting duration = " << meanDtPF / iterAsDouble << " ms" << std::endl;
649 
650 #ifdef VISP_HAVE_DISPLAY
651  if (data.m_grabber.end() && (!data.m_stepbystep)) {
653  vpDisplay::display(data.m_I_orig);
654  vpDisplay::displayText(data.m_I_orig, data.m_ipLegend, "End of sequence reached. Click to exit.", data.m_colorLegend);
655 
657  vpDisplay::flush(data.m_I_orig);
658 
660  vpDisplay::getClick(data.m_I_orig, true);
661  }
662 #endif
663  return 0;
664 }
665 #else
666 int main()
667 {
668  std::cerr << "ViSP must be compiled with C++ standard >= C++11 to use this tutorial." << std::endl;
669  std::cerr << "ViSP must also have a 3rd party enabling display features, such as X11 or OpenCV." << std::endl;
670  return EXIT_FAILURE;
671 }
672 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
vpRowVector transpose() const
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor red
Definition: vpColor.h:217
static const vpColor gray
Definition: vpColor.h:214
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void displayCross(const vpImage< unsigned char > &I, const vpImagePoint &ip, unsigned int size, const vpColor &color, unsigned int thickness=1)
static void flush(const vpImage< unsigned char > &I)
static void displayPoint(const vpImage< unsigned char > &I, const vpImagePoint &ip, const vpColor &color, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
double get_u() const
Definition: vpImagePoint.h:136
double get_v() const
Definition: vpImagePoint.h:147
Definition of the vpImage class member functions.
Definition: vpImage.h:131
unsigned int getWidth() const
Definition: vpImage.h:242
unsigned int getHeight() const
Definition: vpImage.h:181
The class permits to use a Particle Filter.
This class enables real time drawing of 2D or 3D graphics. An instance of the class open a window whi...
Definition: vpPlot.h:112
Contains an M-estimator and various influence function.
Definition: vpRobust.h:84
@ TUKEY
Tukey influence function.
Definition: vpRobust.h:89
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Definition: vpRobust.cpp:130
VISP_EXPORT double measureTimeMicros()
VISP_EXPORT double measureTimeMs()