Visual Servoing Platform  version 3.0.0
vpFeatureBuilderPoint.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 
44 #include <visp3/visual_features/vpFeatureBuilder.h>
45 #include <visp3/visual_features/vpFeatureException.h>
46 #include <visp3/core/vpException.h>
47 
48 #ifdef VISP_HAVE_MODULE_BLOB
49 
90  const vpCameraParameters &cam,
91  const vpDot &d)
92 {
93  try
94  {
95  double x=0, y=0;
96 
97  vpImagePoint cog;
98  cog = d.getCog();
99 
100  vpPixelMeterConversion::convertPoint(cam, cog, x, y) ;
101 
102  s.set_x(x) ;
103  s.set_y(y) ;
104  }
105  catch(...)
106  {
107  vpERROR_TRACE("Error caught") ;
108  throw ;
109  }
110 }
111 
112 
152  const vpCameraParameters &cam,
153  const vpDot2 &d)
154 {
155  try
156  {
157  double x=0, y=0;
158 
159  vpImagePoint cog;
160  cog = d.getCog();
161 
162  vpPixelMeterConversion::convertPoint(cam, cog, x, y) ;
163 
164  s.set_x(x) ;
165  s.set_y(y) ;
166  }
167  catch(...)
168  {
169  vpERROR_TRACE("Error caught") ;
170  throw ;
171  }
172 }
173 #endif //#ifdef VISP_HAVE_MODULE_BLOB
174 
175 
216  const vpCameraParameters &cam,
217  const vpImagePoint &ip)
218 {
219  try
220  {
221  double x=0, y=0;
222 
223  vpPixelMeterConversion::convertPoint(cam, ip, x, y) ;
224 
225  s.set_x(x) ;
226  s.set_y(y) ;
227  }
228  catch(...)
229  {
230  vpERROR_TRACE("Error caught") ;
231  throw ;
232  }
233 }
234 
235 
246 void
248 {
249  try
250  {
251  s.set_x( p.get_x()) ;
252  s.set_y( p.get_y()) ;
253 
254  s.set_Z( p.cP[2]/p.cP[3]) ;
255 
256  if (s.get_Z() < 0)
257  {
258  vpERROR_TRACE("Point is behind the camera ") ;
259  std::cout <<"Z = " << s.get_Z() << std::endl ;
260 
262  "Point is behind the camera ")) ;
263  }
264 
265  if (fabs(s.get_Z()) < 1e-6)
266  {
267  vpERROR_TRACE("Point Z coordinates is null ") ;
268  std::cout <<"Z = " << s.get_Z() << std::endl ;
269 
271  "Point Z coordinates is null")) ;
272  }
273 
274  }
275  catch(...)
276  {
277  vpERROR_TRACE("Error caught") ;
278  throw ;
279  }
280 }
281 
282 
308 void
310  const vpCameraParameters &goodCam,
311  const vpCameraParameters &wrongCam,
312  const vpPoint &p)
313 {
314  try
315  {
316  double x = p.p[0] ;
317  double y = p.p[1] ;
318 
319  s.set_Z( p.cP[2]/p.cP[3]) ;
320 
321  double u=0, v=0;
322  vpMeterPixelConversion::convertPoint(goodCam,x,y,u,v) ;
323  vpPixelMeterConversion::convertPoint(wrongCam,u,v,x,y) ;
324 
325 
326  s.set_x(x) ;
327  s.set_y(y) ;
328  }
329  catch(...)
330  {
331  vpERROR_TRACE("Error caught") ;
332  throw ;
333  }
334 }
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
#define vpERROR_TRACE
Definition: vpDebug.h:391
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)
Point coordinates conversion from pixel coordinates to normalized coordinates in meter...
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:458
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:124
void set_y(const double y)
Class that defines what is a point.
Definition: vpPoint.h:59
vpImagePoint getCog() const
Definition: vpDot2.h:160
void set_x(const double x)
vpColVector cP
Definition: vpTracker.h:77
vpImagePoint getCog() const
Definition: vpDot.h:224
Error that can be emited by the vpBasicFeature class and its derivates.
double get_Z() const
Generic class defining intrinsic camera parameters.
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:456
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:115
void set_Z(const double Z)
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:73