Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpFeatureBuilderSegment.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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  * Segment creation out of dots.
32  *
33  * Authors:
34  * Filip Novotny
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
39 
45 #include <visp3/visual_features/vpFeatureBuilder.h>
46 #include <visp3/core/vpMath.h>
47 
48 #ifdef VISP_HAVE_MODULE_BLOB
49 
60  const vpDot &d1, const vpDot &d2 )
61 {
62  double x1=0, y1=0, x2=0, y2=0;
63 
64  vpPixelMeterConversion::convertPoint(cam, d1.getCog(), x1, y1) ;
65  vpPixelMeterConversion::convertPoint(cam, d2.getCog(), x2, y2) ;
66 
67  double xc = (x1+x2)/2.;
68  double yc = (y1+y2)/2.;
69  double l = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
70 
71  if (s.isNormalized())
72  {
73  s.setXc( xc/l );
74  s.setYc( yc/l );
75  s.setL ( 1/l );
76  }
77  else
78  {
79  s.setXc( xc );
80  s.setYc( yc );
81  s.setL ( l );
82  }
83 
84  s.setAlpha(atan2(y1-y2,x1-x2));
85 }
86 
97  const vpDot2 &d1, const vpDot2 &d2)
98 {
99  double x1=0, y1=0, x2=0, y2=0;
100 
101  vpPixelMeterConversion::convertPoint(cam, d1.getCog(), x1, y1) ;
102  vpPixelMeterConversion::convertPoint(cam, d2.getCog(), x2, y2) ;
103 
104  double xc = (x1+x2)/2.;
105  double yc = (y1+y2)/2.;
106  double l = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
107 
108  if (s.isNormalized())
109  {
110  s.setXc( xc/l );
111  s.setYc( yc/l );
112  s.setL ( 1/l );
113  }
114  else
115  {
116  s.setXc( xc );
117  s.setYc( yc );
118  s.setL ( l );
119  }
120 
121  s.setAlpha(atan2(y1-y2,x1-x2));
122 }
123 #endif //#ifdef VISP_HAVE_MODULE_BLOB
124 
135  const vpImagePoint &ip1, const vpImagePoint &ip2)
136 {
137  double x1=0, y1=0, x2=0, y2=0;
138 
139  vpPixelMeterConversion::convertPoint(cam, ip1, x1, y1) ;
140  vpPixelMeterConversion::convertPoint(cam, ip2, x2, y2) ;
141 
142  double xc = (x1+x2)/2.;
143  double yc = (y1+y2)/2.;
144  double l = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
145 
146  if (s.isNormalized())
147  {
148  s.setXc( xc/l );
149  s.setYc( yc/l );
150  s.setL ( 1/l );
151  }
152  else
153  {
154  s.setXc( xc );
155  s.setYc( yc );
156  s.setL ( l );
157  }
158 
159  s.setAlpha(atan2(y1-y2,x1-x2));
160 }
161 
172 {
173  double x1 = P1.get_x();
174  double y1 = P1.get_y();
175  double x2 = P2.get_x();
176  double y2 = P2.get_y();
177 
178  double Z1 = P1.cP[2]/P1.cP[3];
179  double Z2 = P2.cP[2]/P2.cP[3];
180 
181  s.buildFrom(x1, y1, Z1, x2, y2, Z2);
182 }
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.cpp:458
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:125
void setL(const double val)
Class that defines what is a point.
Definition: vpPoint.h:59
vpImagePoint getCog() const
Definition: vpDot2.h:161
vpColVector cP
Definition: vpTracker.h:77
vpImagePoint getCog() const
Definition: vpDot.h:225
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.cpp:456
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:116
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)
void setXc(const double val)