ViSP  2.8.0
vpFeatureBuilderSegment.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureBuilderLine.cpp 3530 2012-01-03 10:52:12Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  * Segment creation out of dots.
36  *
37  * Authors:
38  * Filip Novotny
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
43 
49 #include <visp/vpFeatureBuilder.h>
50 #include <visp/vpMath.h>
51 
52 
63  const vpDot &d1, const vpDot &d2 )
64 {
65  double x1=0, y1=0, x2=0, y2=0;
66 
67  vpPixelMeterConversion::convertPoint(cam, d1.getCog(), x1, y1) ;
68  vpPixelMeterConversion::convertPoint(cam, d2.getCog(), x2, y2) ;
69 
70  double xc = (x1+x2)/2.;
71  double yc = (y1+y2)/2.;
72  double l = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
73 
74  if (s.isNormalized())
75  {
76  s.setXc( xc/l );
77  s.setYc( yc/l );
78  s.setL ( 1/l );
79  }
80  else
81  {
82  s.setXc( xc );
83  s.setYc( yc );
84  s.setL ( l );
85  }
86 
87  s.setAlpha(atan2(y1-y2,x1-x2));
88 }
89 
100  const vpDot2 &d1, const vpDot2 &d2)
101 {
102  double x1=0, y1=0, x2=0, y2=0;
103 
104  vpPixelMeterConversion::convertPoint(cam, d1.getCog(), x1, y1) ;
105  vpPixelMeterConversion::convertPoint(cam, d2.getCog(), x2, y2) ;
106 
107  double xc = (x1+x2)/2.;
108  double yc = (y1+y2)/2.;
109  double l = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
110 
111  if (s.isNormalized())
112  {
113  s.setXc( xc/l );
114  s.setYc( yc/l );
115  s.setL ( 1/l );
116  }
117  else
118  {
119  s.setXc( xc );
120  s.setYc( yc );
121  s.setL ( l );
122  }
123 
124  s.setAlpha(atan2(y1-y2,x1-x2));
125 }
126 
137  const vpImagePoint &ip1, const vpImagePoint &ip2)
138 {
139  double x1=0, y1=0, x2=0, y2=0;
140 
141  vpPixelMeterConversion::convertPoint(cam, ip1, x1, y1) ;
142  vpPixelMeterConversion::convertPoint(cam, ip2, x2, y2) ;
143 
144  double xc = (x1+x2)/2.;
145  double yc = (y1+y2)/2.;
146  double l = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
147 
148  if (s.isNormalized())
149  {
150  s.setXc( xc/l );
151  s.setYc( yc/l );
152  s.setL ( 1/l );
153  }
154  else
155  {
156  s.setXc( xc );
157  s.setYc( yc );
158  s.setL ( l );
159  }
160 
161  s.setAlpha(atan2(y1-y2,x1-x2));
162 }
163 
174 {
175  double x1 = P1.get_x();
176  double y1 = P1.get_y();
177  double x2 = P2.get_x();
178  double y2 = P2.get_y();
179 
180  double Z1 = P1.cP[2]/P1.cP[3];
181  double Z2 = P2.cP[2]/P2.cP[3];
182 
183  s.buildFrom(x1, y1, Z1, x2, y2, Z2);
184 }
void setAlpha(const double val)
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:131
void setL(const double val)
Class that defines what is a point.
Definition: vpPoint.h:65
vpImagePoint getCog() const
Definition: vpDot2.h:167
vpColVector cP
Definition: vpTracker.h:82
vpImagePoint getCog() const
Definition: vpDot.h:227
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
Generic class defining intrinsic camera parameters.
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.h:136
void setYc(const double val)
void buildFrom(const double x1, const double y1, const double Z1, const double x2, const double y2, const double Z2)
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:118
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)
void setXc(const double val)