ViSP  2.9.0
vpFeatureBuilderPoint.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureBuilderPoint.cpp 4574 2014-01-09 08:48:51Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Conversion between tracker and visual feature point.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
48 #include <visp/vpFeatureBuilder.h>
49 #include <visp/vpFeatureException.h>
50 #include <visp/vpException.h>
51 
52 
94  const vpCameraParameters &cam,
95  const vpDot &d)
96 {
97  try
98  {
99  double x=0, y=0;
100 
101  vpImagePoint cog;
102  cog = d.getCog();
103 
104  vpPixelMeterConversion::convertPoint(cam, cog, x, y) ;
105 
106  s.set_x(x) ;
107  s.set_y(y) ;
108  }
109  catch(...)
110  {
111  vpERROR_TRACE("Error caught") ;
112  throw ;
113  }
114 }
115 
116 
156  const vpCameraParameters &cam,
157  const vpDot2 &d)
158 {
159  try
160  {
161  double x=0, y=0;
162 
163  vpImagePoint cog;
164  cog = d.getCog();
165 
166  vpPixelMeterConversion::convertPoint(cam, cog, x, y) ;
167 
168  s.set_x(x) ;
169  s.set_y(y) ;
170  }
171  catch(...)
172  {
173  vpERROR_TRACE("Error caught") ;
174  throw ;
175  }
176 }
177 
178 
219  const vpCameraParameters &cam,
220  const vpImagePoint &ip)
221 {
222  try
223  {
224  double x=0, y=0;
225 
226  vpPixelMeterConversion::convertPoint(cam, ip, x, y) ;
227 
228  s.set_x(x) ;
229  s.set_y(y) ;
230  }
231  catch(...)
232  {
233  vpERROR_TRACE("Error caught") ;
234  throw ;
235  }
236 }
237 
238 
249 void
251 {
252  try
253  {
254  s.set_x( p.get_x()) ;
255  s.set_y( p.get_y()) ;
256 
257  s.set_Z( p.cP[2]/p.cP[3]) ;
258 
259  if (s.get_Z() < 0)
260  {
261  vpERROR_TRACE("Point is behind the camera ") ;
262  std::cout <<"Z = " << s.get_Z() << std::endl ;
263 
265  "Point is behind the camera ")) ;
266  }
267 
268  if (fabs(s.get_Z()) < 1e-6)
269  {
270  vpERROR_TRACE("Point Z coordinates is null ") ;
271  std::cout <<"Z = " << s.get_Z() << std::endl ;
272 
274  "Point Z coordinates is null")) ;
275  }
276 
277  }
278  catch(...)
279  {
280  vpERROR_TRACE("Error caught") ;
281  throw ;
282  }
283 }
284 
285 
311 void
313  const vpCameraParameters &goodCam,
314  const vpCameraParameters &wrongCam,
315  const vpPoint &p)
316 {
317  try
318  {
319  double x = p.p[0] ;
320  double y = p.p[1] ;
321 
322  s.set_Z( p.cP[2]/p.cP[3]) ;
323 
324  double u=0, v=0;
325  vpMeterPixelConversion::convertPoint(goodCam,x,y,u,v) ;
326  vpPixelMeterConversion::convertPoint(wrongCam,u,v,x,y) ;
327 
328 
329  s.set_x(x) ;
330  s.set_y(y) ;
331  }
332  catch(...)
333  {
334  vpERROR_TRACE("Error caught") ;
335  throw ;
336  }
337 }
338 
339 
340 
341 
342 
343 /*
344  * Local variables:
345  * c-basic-offset: 2
346  * End:
347  */
#define vpERROR_TRACE
Definition: vpDebug.h:395
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 ...
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.h:138
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:127
void set_y(const double y)
Class that defines what is a point.
Definition: vpPoint.h:65
vpImagePoint getCog() const
Definition: vpDot2.h:163
void set_x(const double x)
vpColVector cP
Definition: vpTracker.h:82
vpImagePoint getCog() const
Definition: vpDot.h:223
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.h:136
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:114
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:92
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
vpColVector p
Definition: vpTracker.h:78