Visual Servoing Platform  version 3.5.1 under development (2023-09-22)
vpFeatureBuilderSegment.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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  *
37 *****************************************************************************/
38 
44 #include <visp3/core/vpMath.h>
45 #include <visp3/visual_features/vpFeatureBuilder.h>
46 
47 #ifdef VISP_HAVE_MODULE_BLOB
48 
59 void vpFeatureBuilder::create(vpFeatureSegment &s, const vpCameraParameters &cam, const vpDot &d1, const vpDot &d2)
60 {
61  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
62 
65 
66  double xc = (x1 + x2) / 2.;
67  double yc = (y1 + y2) / 2.;
68  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
69 
70  if (s.isNormalized()) {
71  s.setXc(xc / l);
72  s.setYc(yc / l);
73  s.setL(1 / l);
74  } else {
75  s.setXc(xc);
76  s.setYc(yc);
77  s.setL(l);
78  }
79 
80  s.setAlpha(atan2(y1 - y2, x1 - x2));
81 }
82 
93 void vpFeatureBuilder::create(vpFeatureSegment &s, const vpCameraParameters &cam, const vpDot2 &d1, const vpDot2 &d2)
94 {
95  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
96 
99 
100  double xc = (x1 + x2) / 2.;
101  double yc = (y1 + y2) / 2.;
102  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
103 
104  if (s.isNormalized()) {
105  s.setXc(xc / l);
106  s.setYc(yc / l);
107  s.setL(1 / l);
108  } else {
109  s.setXc(xc);
110  s.setYc(yc);
111  s.setL(l);
112  }
113 
114  s.setAlpha(atan2(y1 - y2, x1 - x2));
115 }
116 #endif //#ifdef VISP_HAVE_MODULE_BLOB
117 
129  const vpImagePoint &ip2)
130 {
131  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
132 
133  vpPixelMeterConversion::convertPoint(cam, ip1, x1, y1);
134  vpPixelMeterConversion::convertPoint(cam, ip2, x2, y2);
135 
136  double xc = (x1 + x2) / 2.;
137  double yc = (y1 + y2) / 2.;
138  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
139 
140  if (s.isNormalized()) {
141  s.setXc(xc / l);
142  s.setYc(yc / l);
143  s.setL(1 / l);
144  } else {
145  s.setXc(xc);
146  s.setYc(yc);
147  s.setL(l);
148  }
149 
150  s.setAlpha(atan2(y1 - y2, x1 - x2));
151 }
152 
164 {
165  double x1 = P1.get_x();
166  double y1 = P1.get_y();
167  double x2 = P2.get_x();
168  double y2 = P2.get_y();
169 
170  double Z1 = P1.cP[2] / P1.cP[3];
171  double Z2 = P2.cP[2] / P2.cP[3];
172 
173  s.buildFrom(x1, y1, Z1, x2, y2, Z2);
174 }
Generic class defining intrinsic camera parameters.
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:124
vpImagePoint getCog() const
Definition: vpDot2.h:177
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
Definition: vpDot.h:112
vpImagePoint getCog() const
Definition: vpDot.h:243
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
void buildFrom(double x1, double y1, double Z1, double x2, double y2, double Z2)
void setAlpha(double val)
void setL(double val)
void setXc(double val)
void setYc(double val)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:77
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:469
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:467
vpColVector cP
Definition: vpTracker.h:72