Visual Servoing Platform  version 3.3.1 under development (2020-10-22)
vpFeatureBuilderSegment.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  * Segment creation out of dots.
33  *
34  * Authors:
35  * Filip Novotny
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
45 #include <visp3/core/vpMath.h>
46 #include <visp3/visual_features/vpFeatureBuilder.h>
47 
48 #ifdef VISP_HAVE_MODULE_BLOB
49 
60 void vpFeatureBuilder::create(vpFeatureSegment &s, const vpCameraParameters &cam, const vpDot &d1, const vpDot &d2)
61 {
62  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
63 
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  s.setXc(xc / l);
73  s.setYc(yc / l);
74  s.setL(1 / l);
75  } else {
76  s.setXc(xc);
77  s.setYc(yc);
78  s.setL(l);
79  }
80 
81  s.setAlpha(atan2(y1 - y2, x1 - x2));
82 }
83 
94 void vpFeatureBuilder::create(vpFeatureSegment &s, const vpCameraParameters &cam, const vpDot2 &d1, const vpDot2 &d2)
95 {
96  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
97 
100 
101  double xc = (x1 + x2) / 2.;
102  double yc = (y1 + y2) / 2.;
103  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
104 
105  if (s.isNormalized()) {
106  s.setXc(xc / l);
107  s.setYc(yc / l);
108  s.setL(1 / l);
109  } else {
110  s.setXc(xc);
111  s.setYc(yc);
112  s.setL(l);
113  }
114 
115  s.setAlpha(atan2(y1 - y2, x1 - x2));
116 }
117 #endif //#ifdef VISP_HAVE_MODULE_BLOB
118 
130  const vpImagePoint &ip2)
131 {
132  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
133 
134  vpPixelMeterConversion::convertPoint(cam, ip1, x1, y1);
135  vpPixelMeterConversion::convertPoint(cam, ip2, x2, y2);
136 
137  double xc = (x1 + x2) / 2.;
138  double yc = (y1 + y2) / 2.;
139  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
140 
141  if (s.isNormalized()) {
142  s.setXc(xc / l);
143  s.setYc(yc / l);
144  s.setL(1 / l);
145  } else {
146  s.setXc(xc);
147  s.setYc(yc);
148  s.setL(l);
149  }
150 
151  s.setAlpha(atan2(y1 - y2, x1 - x2));
152 }
153 
165 {
166  double x1 = P1.get_x();
167  double y1 = P1.get_y();
168  double x2 = P2.get_x();
169  double y2 = P2.get_y();
170 
171  double Z1 = P1.cP[2] / P1.cP[3];
172  double Z2 = P2.cP[2] / P2.cP[3];
173 
174  s.buildFrom(x1, y1, Z1, x2, y2, Z2);
175 }
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
void setL(double val)
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:126
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:81
void setYc(double val)
vpColVector cP
Definition: vpTracker.h:77
void buildFrom(double x1, double y1, double Z1, double x2, double y2, double Z2)
vpImagePoint getCog() const
Definition: vpDot.h:215
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
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:458
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:87
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void setXc(double val)
void setAlpha(double val)