Visual Servoing Platform  version 3.6.1 under development (2024-11-21)
vpFeatureBuilderPoint.cpp
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  * Description:
31  * Conversion between tracker and visual feature point.
32  */
33 
39 #include <visp3/core/vpDebug.h>
40 #include <visp3/core/vpException.h>
41 #include <visp3/visual_features/vpFeatureBuilder.h>
42 #include <visp3/visual_features/vpFeatureException.h>
43 
44 BEGIN_VISP_NAMESPACE
45 #ifdef VISP_HAVE_MODULE_BLOB
91 {
92  try {
93  double x = 0, y = 0;
94 
95  vpImagePoint cog;
96  cog = d.getCog();
97 
99 
100  s.set_x(x);
101  s.set_y(y);
102  }
103  catch (...) {
104  vpERROR_TRACE("Error caught");
105  throw;
106  }
107 }
108 
152 {
153  try {
154  double x = 0, y = 0;
155 
156  vpImagePoint cog;
157  cog = d.getCog();
158 
159  vpPixelMeterConversion::convertPoint(cam, cog, x, y);
160 
161  s.set_x(x);
162  s.set_y(y);
163  }
164  catch (...) {
165  vpERROR_TRACE("Error caught");
166  throw;
167  }
168 }
169 #endif //#ifdef VISP_HAVE_MODULE_BLOB
170 
214 {
215  try {
216  double x = 0, y = 0;
217 
219 
220  s.set_x(x);
221  s.set_y(y);
222  }
223  catch (...) {
224  vpERROR_TRACE("Error caught");
225  throw;
226  }
227 }
228 
244 {
245  try {
246  s.set_x(p.get_x());
247  s.set_y(p.get_y());
248 
249  s.set_Z(p.cP[2] / p.cP[3]);
250 
251  if (s.get_Z() < 0) {
252  vpERROR_TRACE("Point is behind the camera ");
253  std::cout << "Z = " << s.get_Z() << std::endl;
254 
255  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point is behind the camera "));
256  }
257 
258  if (fabs(s.get_Z()) < 1e-6) {
259  vpERROR_TRACE("Point Z coordinates is null ");
260  std::cout << "Z = " << s.get_Z() << std::endl;
261 
262  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z coordinates is null"));
263  }
264 
265  }
266  catch (...) {
267  vpERROR_TRACE("Error caught");
268  throw;
269  }
270 }
271 
304  const vpPoint &p)
305 {
306  try {
307  double x = p.p[0];
308  double y = p.p[1];
309 
310  s.set_Z(p.cP[2] / p.cP[3]);
311 
312  double u = 0, v = 0;
313  vpMeterPixelConversion::convertPoint(goodCam, x, y, u, v);
314  vpPixelMeterConversion::convertPoint(wrongCam, u, v, x, y);
315 
316  s.set_x(x);
317  s.set_y(y);
318  }
319  catch (...) {
320  vpERROR_TRACE("Error caught");
321  throw;
322  }
323 }
324 END_VISP_NAMESPACE
Generic class defining intrinsic camera parameters.
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:125
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
Definition: vpDot.h:116
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Error that can be emitted by the vpBasicFeature class and its derivates.
@ badInitializationError
Wrong feature initialization.
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void set_y(double y)
void set_x(double x)
double get_Z() const
void set_Z(double Z)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
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
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:422
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:420
vpColVector cP
Definition: vpTracker.h:73
vpColVector p
Definition: vpTracker.h:69