Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpTutoMeanSquareFitting.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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
44namespace tutorial
45{
50class vpTutoMeanSquareFitting
51{
52public:
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
106 template<typename T>
107 void display(const VISP_NAMESPACE_ADDRESSING vpImage<T> &I, const VISP_NAMESPACE_ADDRESSING vpColor &color,
108 const unsigned int &vertPosLegend, const unsigned int &horPosLegend)
109 {
110 unsigned int width = I.getWidth();
111 for (unsigned int u = 0; u < width; ++u) {
112 int v = static_cast<int>(model(u));
113 VISP_NAMESPACE_ADDRESSING vpDisplay::displayPoint(I, v, u, color, 1);
114 VISP_NAMESPACE_ADDRESSING vpDisplay::displayText(I, vertPosLegend, horPosLegend, "Least-mean square model", color);
115 }
116 }
117#endif
118
122 inline void reinit()
123 {
124 m_isFitted = false;
125 }
126
127 inline vpTutoMeanSquareFitting &operator=(const vpTutoMeanSquareFitting &other)
128 {
129 m_model = other.m_model;
130 m_isFitted = other.m_isFitted;
131 return *this;
132 }
133
139 inline VISP_NAMESPACE_ADDRESSING vpColVector getCoeffs() const
140 {
141 return m_model.toVpColVector();
142 }
143
149 inline const vpTutoParabolaModel &getModel() const
150 {
151 return m_model;
152 }
153
154protected:
155 unsigned int m_degree;
156 unsigned int m_height;
157 unsigned int m_width;
158 vpTutoParabolaModel m_model;
159 bool m_isFitted;
160};
161}
162#endif
163#endif
164#endif
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)
unsigned int getWidth() const
Definition vpImage.h:242