Visual Servoing Platform  version 3.3.0 under development (2020-02-17)
vpFeatureBuilderPoint.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Conversion between tracker and visual feature point.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
44 #include <visp3/core/vpException.h>
45 #include <visp3/visual_features/vpFeatureBuilder.h>
46 #include <visp3/visual_features/vpFeatureException.h>
47 
48 #ifdef VISP_HAVE_MODULE_BLOB
49 
94 {
95  try {
96  double x = 0, y = 0;
97 
98  vpImagePoint cog;
99  cog = d.getCog();
100 
101  vpPixelMeterConversion::convertPoint(cam, cog, x, y);
102 
103  s.set_x(x);
104  s.set_y(y);
105  } catch (...) {
106  vpERROR_TRACE("Error caught");
107  throw;
108  }
109 }
110 
154 {
155  try {
156  double x = 0, y = 0;
157 
158  vpImagePoint cog;
159  cog = d.getCog();
160 
161  vpPixelMeterConversion::convertPoint(cam, cog, x, y);
162 
163  s.set_x(x);
164  s.set_y(y);
165  } catch (...) {
166  vpERROR_TRACE("Error caught");
167  throw;
168  }
169 }
170 #endif //#ifdef VISP_HAVE_MODULE_BLOB
171 
215 {
216  try {
217  double x = 0, y = 0;
218 
220 
221  s.set_x(x);
222  s.set_y(y);
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  } catch (...) {
266  vpERROR_TRACE("Error caught");
267  throw;
268  }
269 }
270 
303  const vpPoint &p)
304 {
305  try {
306  double x = p.p[0];
307  double y = p.p[1];
308 
309  s.set_Z(p.cP[2] / p.cP[3]);
310 
311  double u = 0, v = 0;
312  vpMeterPixelConversion::convertPoint(goodCam, x, y, u, v);
313  vpPixelMeterConversion::convertPoint(wrongCam, u, v, x, y);
314 
315  s.set_x(x);
316  s.set_y(y);
317  } catch (...) {
318  vpERROR_TRACE("Error caught");
319  throw;
320  }
321 }
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
#define vpERROR_TRACE
Definition: vpDebug.h:393
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
void set_y(double y)
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:126
void set_x(double x)
Class that defines what is a point.
Definition: vpPoint.h:58
vpColVector cP
Definition: vpTracker.h:75
vpImagePoint getCog() const
Definition: vpDot.h:221
void set_Z(double Z)
Error that can be emited by the vpBasicFeature class and its derivates.
Generic class defining intrinsic camera parameters.
double get_Z() const
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:431
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:433
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:115
vpImagePoint getCog() const
Definition: vpDot2.h:161
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
vpColVector p
Definition: vpTracker.h:71