Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpTutoMeanSquareFitting.h
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 
31 #ifndef VP_TUTO_MEAN_SQUARE_FITTING_H
32 #define VP_TUTO_MEAN_SQUARE_FITTING_H
33 
34 #include <visp3/core/vpConfig.h>
35 #include <visp3/core/vpDisplay.h>
36 #include <visp3/core/vpImagePoint.h>
37 #include <visp3/core/vpMatrix.h>
38 #include <visp3/core/vpRobust.h>
39 
40 #include "vpTutoParabolaModel.h"
41 
42 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
43 #ifndef DOXYGEN_SHOULD_SKIP_THIS
44 namespace tutorial
45 {
50 class vpTutoMeanSquareFitting
51 {
52 public:
60  vpTutoMeanSquareFitting(const unsigned int &degree, const unsigned int &height, const unsigned int &width);
61 
68  void fit(const std::vector<VISP_NAMESPACE_ADDRESSING vpImagePoint> &pts);
69 
76  double evaluate(const std::vector<VISP_NAMESPACE_ADDRESSING vpImagePoint> &pts);
77 
84  double evaluate(const VISP_NAMESPACE_ADDRESSING vpImagePoint &pt);
85 
94  double model(const double &u);
95 
96 #ifdef VISP_HAVE_DISPLAY
104  template<typename T>
105  void display(const VISP_NAMESPACE_ADDRESSING vpImage<T> &I, const VISP_NAMESPACE_ADDRESSING vpColor &color,
106  const unsigned int &vertPosLegend, const unsigned int &horPosLegend)
107  {
108  unsigned int width = I.getWidth();
109  for (unsigned int u = 0; u < width; ++u) {
110  int v = static_cast<int>(model(u));
111  VISP_NAMESPACE_ADDRESSING vpDisplay::displayPoint(I, v, u, color, 1);
112  VISP_NAMESPACE_ADDRESSING vpDisplay::displayText(I, vertPosLegend, horPosLegend, "Least-mean square model", color);
113  }
114  }
115 #endif
116 
120  inline void reinit()
121  {
122  m_isFitted = false;
123  }
124 
125  inline vpTutoMeanSquareFitting &operator=(const vpTutoMeanSquareFitting &other)
126  {
127  m_model = other.m_model;
128  m_isFitted = other.m_isFitted;
129  return *this;
130  }
131 
137  inline VISP_NAMESPACE_ADDRESSING vpColVector getCoeffs() const
138  {
139  return m_model.toVpColVector();
140  }
141 
147  inline const vpTutoParabolaModel &getModel() const
148  {
149  return m_model;
150  }
151 
152 protected:
153  unsigned int m_degree;
154  unsigned int m_height;
155  unsigned int m_width;
156  vpTutoParabolaModel m_model;
157  bool m_isFitted;
158 };
159 }
160 #endif
161 #endif
162 #endif
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
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
Definition of the vpImage class member functions.
Definition: vpImage.h:131
unsigned int getWidth() const
Definition: vpImage.h:242