Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpFeatureVanishingPoint.cpp
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 * Description:
31 * 2D vanishing point visual feature (Z coordinate in 3D space is infinity)
32 *
33 * Authors:
34 * Odile Bourquardez
35 */
36
41#include <visp3/visual_features/vpBasicFeature.h>
42#include <visp3/visual_features/vpFeatureVanishingPoint.h>
43
44// Exception
45#include <visp3/core/vpException.h>
46#include <visp3/visual_features/vpFeatureException.h>
47
48// Debug trace
49#include <visp3/core/vpDebug.h>
50
51// math
52#include <visp3/core/vpMath.h>
53
54#include <visp3/core/vpFeatureDisplay.h>
55
61{
62 // Feature dimension
63 dim_s = 5;
64 nbParameters = 5;
65 m_select = 0;
66
67 // memory allocation
68 s.resize(dim_s);
69 if (flags == nullptr)
70 flags = new bool[nbParameters];
71 for (unsigned int i = 0; i < nbParameters; i++)
72 flags[i] = false;
73}
74
77
80{
81 s[0] = x;
82 flags[0] = true;
83 m_select |= selectX();
84}
85
87double vpFeatureVanishingPoint::get_x() const { return s[0]; }
88
91{
92 s[1] = y;
93 flags[1] = true;
94 m_select |= selectY();
95}
96
98double vpFeatureVanishingPoint::get_y() const { return s[1]; }
99
101void vpFeatureVanishingPoint::set_xy(double x, double y)
102{
103 set_x(x);
104 set_y(y);
105 m_select = selectX() | selectY();
106}
107
110{
111 s[2] = one_over_rho;
112 flags[2] = true;
114}
115
117void vpFeatureVanishingPoint::setAtanOneOverRho(double atan_one_over_rho)
118{
119 s[3] = atan_one_over_rho;
120 flags[3] = true;
122}
123
125double vpFeatureVanishingPoint::getOneOverRho() const { return s[2]; }
126
129
132{
133 s[4] = alpha;
134 flags[4] = true;
136}
137
139double vpFeatureVanishingPoint::getAlpha() const { return s[4]; }
140
150{
151 vpMatrix L;
152
153 L.resize(0, 6);
154
156 for (unsigned int i = 0; i < nbParameters; i++) {
157 if (flags[i] == false) {
158 switch (i) {
159 case 0:
160 vpTRACE("Warning !!! The interaction matrix is computed but x was not set yet");
161 break;
162 case 1:
163 vpTRACE("Warning !!! The interaction matrix is computed but y was not set yet");
164 break;
165 case 2:
166 vpTRACE("Warning !!! The interaction matrix is computed but 1/rho was not set yet");
167 break;
168 case 3:
169 vpTRACE("Warning !!! The interaction matrix is computed but atan(1/rho) was not set yet");
170 break;
171 case 4:
172 vpTRACE("Warning !!! The interaction matrix is computed but alpha was not set yet");
173 break;
174 default:
175 vpTRACE("Problem during the reading of the variable flags");
176 }
177 }
178 }
179 resetFlags();
180 }
181
182 if (vpFeatureVanishingPoint::selectX() & select) {
183 double x = get_x();
184 double y = get_y();
185 vpMatrix Lx(1, 6);
186 Lx = 0;
187
188 Lx[0][0] = 0.;
189 Lx[0][1] = 0.;
190 Lx[0][2] = 0.;
191 Lx[0][3] = x * y;
192 Lx[0][4] = -(1 + x * x);
193 Lx[0][5] = y;
194
195 L = vpMatrix::stack(L, Lx);
196 }
197
198 if (vpFeatureVanishingPoint::selectY() & select) {
199 double x = get_x();
200 double y = get_y();
201 vpMatrix Ly(1, 6);
202 Ly = 0;
203
204 Ly[0][0] = 0;
205 Ly[0][1] = 0.;
206 Ly[0][2] = 0.;
207 Ly[0][3] = 1 + y * y;
208 Ly[0][4] = -x * y;
209 Ly[0][5] = -x;
210
211 L = vpMatrix::stack(L, Ly);
212 }
213
215 double one_over_rho = getOneOverRho();
216 double alpha = getAlpha();
217 vpMatrix Lone_over_rho(1, 6);
218 double rho2 = 1. + one_over_rho * one_over_rho;
219
220 Lone_over_rho[0][0] = 0.;
221 Lone_over_rho[0][1] = 0.;
222 Lone_over_rho[0][2] = 0.;
223 Lone_over_rho[0][3] = -rho2 * sin(alpha);
224 Lone_over_rho[0][4] = rho2 * cos(alpha);
225 Lone_over_rho[0][5] = 0.;
226
227 L = vpMatrix::stack(L, Lone_over_rho);
228 }
229
231 double alpha = getAlpha();
232 vpMatrix Latan_one_over_rho(1, 6);
233
234 Latan_one_over_rho[0][0] = 0.;
235 Latan_one_over_rho[0][1] = 0.;
236 Latan_one_over_rho[0][2] = 0.;
237 Latan_one_over_rho[0][3] = -sin(alpha);
238 Latan_one_over_rho[0][4] = cos(alpha);
239 Latan_one_over_rho[0][5] = 0.;
240
241 L = vpMatrix::stack(L, Latan_one_over_rho);
242 }
243
245 double one_over_rho = getOneOverRho();
246 double alpha = getAlpha();
247 vpMatrix Lalpha(1, 6);
248
249 Lalpha[0][0] = 0;
250 Lalpha[0][1] = 0.;
251 Lalpha[0][2] = 0.;
252 Lalpha[0][3] = cos(alpha) * one_over_rho;
253 Lalpha[0][4] = sin(alpha) * one_over_rho;
254 Lalpha[0][5] = -1.;
255
256 L = vpMatrix::stack(L, Lalpha);
257 }
258
259 return L;
260}
261
274{
275 vpColVector e(0);
276
277 if (vpFeatureVanishingPoint::selectX() & select) {
278 vpColVector ex(1);
279 ex[0] = s[0] - s_star[0];
280
281 e = vpColVector::stack(e, ex);
282 }
283
284 if (vpFeatureVanishingPoint::selectY() & select) {
285 vpColVector ey(1);
286 ey[0] = s[1] - s_star[1];
287 e = vpColVector::stack(e, ey);
288 }
289
291 vpColVector e_one_over_rho(1);
292 e_one_over_rho[0] = s[2] - s_star[2];
293
294 e = vpColVector::stack(e, e_one_over_rho);
295 }
296
298 vpColVector e_atan_one_over_rho(1);
299 e_atan_one_over_rho[0] = s[3] - s_star[3];
300
301 e = vpColVector::stack(e, e_atan_one_over_rho);
302 }
303
305 vpColVector e_alpha(1);
306 double err = s[4] - s_star[4];
307
308 if (err < -M_PI)
309 err += 2 * M_PI;
310 if (err > M_PI)
311 err -= 2 * M_PI;
312
313 e_alpha[0] = err;
314 e = vpColVector::stack(e, e_alpha);
315 }
316
317 return e;
318}
319
328void vpFeatureVanishingPoint::print(unsigned int select) const
329{
330 std::cout << "Vanishing point:";
332 std::cout << " x=" << get_x();
334 std::cout << " y=" << get_y();
336 std::cout << " 1/rho=" << getOneOverRho();
337 }
339 std::cout << " atan(1/rho)=" << getAtanOneOverRho();
340 }
342 std::cout << " alpha=" << getAlpha();
343 }
344 std::cout << std::endl;
345}
346
349{
350 set_xy(x, y);
351 return *this;
352}
353
363 const vpColor &color, unsigned int thickness) const
364{
366 double x, y;
367 x = get_x();
368 y = get_y();
369
370 vpFeatureDisplay::displayPoint(x, y, cam, I, color, thickness);
371 }
373 double one_over_rho = getOneOverRho();
374 double alpha = getAlpha();
375 double x = cos(alpha) / one_over_rho;
376 double y = sin(alpha) / one_over_rho;
377 vpFeatureDisplay::displayPoint(x, y, cam, I, color, thickness);
378 }
380 double atan_one_over_rho = getAtanOneOverRho();
381 double alpha = getAlpha();
382 double x = cos(alpha) / tan(atan_one_over_rho);
383 double y = sin(alpha) / tan(atan_one_over_rho);
384 vpFeatureDisplay::displayPoint(x, y, cam, I, color, thickness);
385 }
386}
387
397 unsigned int thickness) const
398{
400 double x, y;
401 x = get_x();
402 y = get_y();
403
404 vpFeatureDisplay::displayPoint(x, y, cam, I, color, thickness);
405 }
407 double one_over_rho = getOneOverRho();
408 double alpha = getAlpha();
409 double x = cos(alpha) / one_over_rho;
410 double y = sin(alpha) / one_over_rho;
411 vpFeatureDisplay::displayPoint(x, y, cam, I, color, thickness);
412 }
414 double atan_one_over_rho = getAtanOneOverRho();
415 double alpha = getAlpha();
416 double x = cos(alpha) / tan(atan_one_over_rho);
417 double y = sin(alpha) / tan(atan_one_over_rho);
418 vpFeatureDisplay::displayPoint(x, y, cam, I, color, thickness);
419 }
420}
421
430
433
436
441
446
451END_VISP_NAMESPACE
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition vpArray2D.h:448
vpColVector s
State of the visual feature.
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
unsigned int dim_s
Dimension of the visual feature.
static const unsigned int FEATURE_LINE[32]
vpBasicFeatureDeallocatorType deallocate
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
void stack(double d)
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static void displayPoint(double x, double y, const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1)
static unsigned int selectAtanOneOverRho()
vpFeatureVanishingPoint * duplicate() const VP_OVERRIDE
void set_y(double y)
Set vanishing point feature value.
void setAlpha(double alpha)
Set vanishing point feature value.
double getOneOverRho() const
Get vanishing point feature value.
double getAlpha() const
Get vanishing point feature value.
void setAtanOneOverRho(double atan_one_over_rho)
Set vanishing point feature value.
vpColVector error(const vpBasicFeature &s_star, unsigned int select=(vpFeatureVanishingPoint::selectX()|vpFeatureVanishingPoint::selectY())) VP_OVERRIDE
void setOneOverRho(double one_over_rho)
Set vanishing point feature value.
double getAtanOneOverRho() const
Get vanishing point feature value.
void set_xy(double x, double y)
Set vanishing point visual feature from cartesian coordinates. Same as buildFrom().
static unsigned int selectX()
Select visual feature .
static unsigned int selectOneOverRho()
vpFeatureVanishingPoint & buildFrom(const double &x, const double &y)
Set vanishing point visual feature from cartesian coordinates. Same as set_xy().
double get_y() const
Get vanishing point feature value.
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
vpMatrix interaction(unsigned int select=(vpFeatureVanishingPoint::selectX()|vpFeatureVanishingPoint::selectY())) VP_OVERRIDE
double get_x() const
Get vanishing point feature value.
vpFeatureVanishingPoint()
Default constructor that calls init().
static unsigned int selectY()
Select visual feature .
void print(unsigned int select=(vpFeatureVanishingPoint::selectX()|vpFeatureVanishingPoint::selectY())) const VP_OVERRIDE
void set_x(double x)
Set vanishing point feature value.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
void stack(const vpMatrix &A)
#define vpTRACE
Definition vpDebug.h:450