Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpMomentAlpha.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2023 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 * Description:
31 * Alpha moment descriptor for in-plane orientation.
32 */
33
38
39#ifndef _vpMomentAlpha_h_
40#define _vpMomentAlpha_h_
41
42#include <visp3/core/vpMoment.h>
43
103 vpMomentObject objRef(3); // Reference object. Must be of order 3 because we will
104 // need the 3rd order centered moments
105
106 objRef.setType(vpMomentObject::DENSE_POLYGON); // Object is the inner part of a polygon
107 objRef.fromVector(vec_p); // Init the dense object with the polygon
108
109 vpMomentDatabase dbRef; // Reference database
110 vpMomentGravityCenter gRef; // Declaration of gravity center
111 vpMomentCentered mcRef; // Centered moments
112 vpMomentAlpha alphaRef; // Declare alpha as reference
113
114 gRef.linkTo(dbRef); // Add gravity center to database
115 mcRef.linkTo(dbRef); // Add centered moments
116 alphaRef.linkTo(dbRef); // Add alpha depending on centered moments
117
118 dbRef.updateAll(objRef); // All of the moments must be updated, not just alpha
119
120 gRef.compute(); // Compute the moment
121 mcRef.compute(); // Compute centered moments AFTER gravity center
122 alphaRef.compute(); // Compute alpha AFTER centered moments.
123
124 // The order of values in the vector must be as follows: mu30 mu21 mu12 mu03
125 std::vector<double> mu3ref = {mcRef.get(3,0), mcRef.get(2,1), mcRef.get(1,2), mcRef.get(0,3)};
126
127 std::cout << "--- Reference object ---" << std::endl;
128 std::cout << "alphaRef=" << vpMath::deg(alphaRef.get()) << " deg" << std::endl << "mu3="; // print reference alpha
129 std::for_each (mu3ref.begin(), mu3ref.end(), print);
130 std::cout << std::endl;
131
134 vec_p.clear();
135
136 p.set_x(-3); p.set_y(1); // Coordinates in meters in the image plane (vertex 4)
137 vec_p.push_back(p);
138 p.set_x(-3); p.set_y(0); // Coordinates in meters in the image plane (vertex 3)
139 vec_p.push_back(p);
140 p.set_x(2); p.set_y(-2); // Coordinates in meters in the image plane (vertex 2)
141 vec_p.push_back(p);
142 p.set_x(1); p.set_y(-1); // Coordinates in meters in the image plane (vertex 1)
143 vec_p.push_back(p);
144
145 vpMomentObject obj(3); // Second object. Order 3 is also required because of the Alpha
146 // will compare third-order centered moments to given reference.
147
148 obj.setType(vpMomentObject::DENSE_POLYGON); // Object is the inner part of a polygon
149 obj.fromVector(vec_p); // Init the dense object with the polygon
150
151 vpMomentDatabase db; // Database
152 vpMomentGravityCenter g; // Declaration of gravity center
153 vpMomentCentered mc; // mc contains centered moments
154 vpMomentAlpha alpha(mu3ref, alphaRef.get()); // Declare alpha as relative to a reference
155
156 g.linkTo(db); // Add gravity center to database
157 mc.linkTo(db); // Add centered moments
158 alpha.linkTo(db); // Add alpha depending on centered moments
159
160 db.updateAll(obj); // All of the moments must be updated
161
162 g.compute(); // Compute the moment
163 mc.compute(); // Compute centered moments AFTER gravity center
164 alpha.compute(); // Compute alpha AFTER centered moments.
165
166 std::cout << "--- current object ---" << std::endl;
167 std::cout << "alpha=" << vpMath::deg(alpha.get()) << " deg" << std::endl;
168
169 return 0;
170}
171 \endcode
172This program outputs:
173\code
174--- Reference object ---
175alphaRef=25.3019 deg
176mu3=1.80552 0.921882 0.385828 0.122449
177--- current object ---
178alpha=-25.3019 deg
179\endcode
180
181 There is also testMomentAlpha.cpp example that shows how to compute alpha in the range \f$ [-\pi ; \pi] \f$
182 using arrow images as input. The code is given below:
183 \include testMomentAlpha.cpp
184
185 From the first image we compute the 3rd order centered moments and the value of the reference alpha
186 that is than used to compute the alpha moment in the range \f$ [-\pi ; \pi] \f$. Running this example you will get:
187 \code
188alpha expected 0 computed -0.128108 deg
189alpha expected 45 computed 44.8881 deg
190alpha expected 90 computed 89.8719 deg
191alpha expected 135 computed 134.888 deg
192alpha expected 180 computed 179.872 deg
193alpha expected -135 computed -135.112 deg
194alpha expected -90 computed -90.1281 deg
195alpha expected -45 computed -45.1119 deg
196 \endcode
197
198 Shortcuts for quickly getting those references exist in vpMomentCommon.
199
200 This moment depends on vpMomentCentered.
201*/
202class VISP_EXPORT vpMomentAlpha : public vpMoment
203{
204private:
205 bool m_isRef;
206 bool m_symmetric;
207 std::vector<double> m_mu3Ref;
208 double m_alphaRef;
209 double m_symmetricThreshold;
210
211public:
213 vpMomentAlpha(const std::vector<double> &mu3_ref, double alpha_ref, double threshold = 1e-6);
214 virtual ~vpMomentAlpha(){};
215
216 void compute();
220 double get() const { return values[0]; }
224 const char *name() const { return "vpMomentAlpha"; }
225
230 inline bool is_ref() const
231 {
232 if (m_isRef)
233 return true;
234 else
235 return false;
236 }
237
242 inline bool is_symmetric() const
243 {
244 if (m_symmetric)
245 return true;
246 else
247 return false;
248 }
249
250 friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpMomentAlpha &v);
251 void printDependencies(std::ostream &os) const;
252};
253
254#endif
This class defines the orientation of the object inside the plane parallel to the object.
bool is_symmetric() const
bool is_ref() const
double get() const
virtual ~vpMomentAlpha()
const char * name() const
std::vector< double > values
Definition vpMoment.h:113
virtual void compute()=0
friend VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpMoment &m)
Definition vpMoment.cpp:122
virtual void printDependencies(std::ostream &os) const
Definition vpMoment.cpp:135