Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpFeatureBuilderVanishingPoint.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 * Conversion between tracker and visual feature vanishing point.
32 */
33
39#include <visp3/core/vpException.h>
40#include <visp3/visual_features/vpFeatureBuilder.h>
41#include <visp3/visual_features/vpFeatureException.h>
42
60void vpFeatureBuilder::create(vpFeatureVanishingPoint &s, const vpPoint &p, unsigned int select)
61{
63 s.set_x(p.get_x());
64 s.set_y(p.get_y());
65 }
66 else if ((vpFeatureVanishingPoint::selectOneOverRho() & select) ||
68 double x = p.get_x();
69 double y = p.get_y();
70
71 s.setOneOverRho(1. / sqrt(x * x + y * y));
72 s.setAlpha(atan2(y, x));
73 }
74}
75
97 unsigned int select)
98{
100 double rho_l = L1.getRho();
101 double rho_r = L2.getRho();
102 double theta_l = L1.getTheta();
103 double theta_r = L2.getTheta();
104 double c_l = cos(theta_l);
105 double c_r = cos(theta_r);
106 double s_l = sin(theta_l);
107 double s_r = sin(theta_r);
108
109 double min = 0.0001;
110 if (fabs(theta_r - theta_l) < min || fabs(fabs(theta_r - theta_l) - M_PI) < min ||
111 fabs(fabs(theta_r - theta_l) - 2 * M_PI) < min) {
112 vpCERROR << "There is no vanishing point : the lines are parallel in the "
113 "image plane"
114 << std::endl;
116 "There is no vanishing point : the lines are "
117 "parallel in the image plane"));
118 }
119
120 double y = (rho_r * c_l - rho_l * c_r) / (-s_l * c_r + s_r * c_l);
121 double x = (rho_r * s_l - rho_l * s_r) / (-c_l * s_r + c_r * s_l);
122
123 s.set_x(x);
124 s.set_y(y);
125 }
126 else if ((vpFeatureVanishingPoint::selectOneOverRho() & select) ||
128 double rho_1 = L1.getRho();
129 double theta_1 = L1.getTheta();
130 double rho_2 = L2.getRho();
131 double theta_2 = L2.getTheta();
132
133 double theta_diff = theta_1 - theta_2;
134
135 double denom = sqrt(rho_1 * rho_1 + rho_2 * rho_2 - 2 * rho_1 * rho_2 * cos(theta_diff));
136 double one_over_rho = sin(theta_diff) / denom;
137 double alpha = atan2(rho_1 * cos(theta_2) - rho_2 * cos(theta_1), rho_2 * sin(theta_1) - rho_1 * sin(theta_2));
138
139 s.setOneOverRho(one_over_rho);
140 s.setAlpha(alpha);
141 }
142}
143
165void vpFeatureBuilder::create(vpFeatureVanishingPoint &s, const vpLine &L1, const vpLine &L2, unsigned int select)
166{
167 vpFeatureLine l1, l2;
170
171 vpFeatureBuilder::create(s, l1, l2, select);
172}
173
194 const vpImagePoint &line1_ip2, const vpImagePoint &line2_ip1,
195 const vpImagePoint &line2_ip2, unsigned int select)
196{
197 double x1 = 0, y1 = 0;
198 double x2 = 0, y2 = 0;
199
200 // First line
201 vpPixelMeterConversion::convertPoint(cam, line1_ip1, x1, y1);
202 vpPixelMeterConversion::convertPoint(cam, line1_ip2, x2, y2);
203
204 double theta_1 = atan2(-(x1 - x2), y1 - y2);
205 double rho_1 = ((x1 + x2) * cos(theta_1) + (y1 + y2) * sin(theta_1)) / 2.;
206
207 // Second line
208 vpPixelMeterConversion::convertPoint(cam, line2_ip1, x1, y1);
209 vpPixelMeterConversion::convertPoint(cam, line2_ip2, x2, y2);
210
211 double theta_2 = atan2(-(x1 - x2), y1 - y2);
212 double rho_2 = ((x1 + x2) * cos(theta_2) + (y1 + y2) * sin(theta_2)) / 2.;
213
215 double min = 0.0001;
216 double theta_diff = theta_1 - theta_2;
217
218 if (fabs(theta_diff) < min || fabs(fabs(theta_diff) - M_PI) < min || fabs(fabs(theta_diff) - 2 * M_PI) < min) {
220 "There is no vanishing point : the lines are parallel in the image plane"));
221 }
222
223 double x = (sin(theta_1) * rho_2 - sin(theta_2) * rho_1) / sin(theta_diff);
224 double y = (cos(theta_2) * rho_1 - cos(theta_1) * rho_2) / sin(theta_diff);
225
226 s.set_x(x);
227 s.set_y(y);
228 }
229 else if ((vpFeatureVanishingPoint::selectOneOverRho() & select)) {
230 double theta_diff = theta_1 - theta_2;
231 double denom = sqrt(rho_1 * rho_1 + rho_2 * rho_2 - 2 * rho_1 * rho_2 * cos(theta_diff));
232 double one_over_rho = sin(theta_diff) / denom;
233 // if (one_over_rho < 0) {
234 // one_over_rho = -one_over_rho;
235 // }
236 double alpha = atan2(rho_1 * cos(theta_2) - rho_2 * cos(theta_1), rho_2 * sin(theta_1) - rho_1 * sin(theta_2));
237
238 s.setOneOverRho(one_over_rho);
239 s.setAlpha(alpha);
240 }
241 else if ((vpFeatureVanishingPoint::selectAtanOneOverRho() & select)) {
242 double theta_diff = theta_1 - theta_2;
243 double denom = sqrt(rho_1 * rho_1 + rho_2 * rho_2 - 2 * rho_1 * rho_2 * cos(theta_diff));
244 double alpha = atan2(rho_1 * cos(theta_2) - rho_2 * cos(theta_1), rho_2 * sin(theta_1) - rho_1 * sin(theta_2));
245 double one_over_rho = sin(theta_diff) / denom;
246 double atan_one_over_rho = atan2(sin(theta_diff), denom);
247
248 // if (one_over_rho < 0) {
249 // one_over_rho = -one_over_rho;
250 // }
251
252 s.setOneOverRho(one_over_rho);
253 s.setAtanOneOverRho(atan_one_over_rho);
254 s.setAlpha(alpha);
255 }
256}
257END_VISP_NAMESPACE
Generic class defining intrinsic camera parameters.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ fatalError
Fatal error.
Definition vpException.h:72
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Error that can be emitted by the vpBasicFeature class and its derivates.
@ badInitializationError
Wrong feature initialization.
Class that defines a 2D line visual feature which is composed by two parameters that are and ,...
double getTheta() const
double getRho() const
static unsigned int selectAtanOneOverRho()
static unsigned int selectX()
Select visual feature .
static unsigned int selectOneOverRho()
static unsigned int selectY()
Select visual feature .
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Class that defines a 3D line in the object frame and allows forward projection of the line in the cam...
Definition vpLine.h:103
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
#define vpCERROR
Definition vpDebug.h:393