Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpFeatureBuilderSegment.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
39 #include <visp3/core/vpMath.h>
40 #include <visp3/visual_features/vpFeatureBuilder.h>
41 
42 BEGIN_VISP_NAMESPACE
43 #ifdef VISP_HAVE_MODULE_BLOB
44 
53  void vpFeatureBuilder::create(vpFeatureSegment &s, const vpCameraParameters &cam, const vpDot &d1, const vpDot &d2)
54 {
55  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
56 
59 
60  double xc = (x1 + x2) / 2.;
61  double yc = (y1 + y2) / 2.;
62  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
63 
64  if (s.isNormalized()) {
65  s.setXc(xc / l);
66  s.setYc(yc / l);
67  s.setL(1 / l);
68  }
69  else {
70  s.setXc(xc);
71  s.setYc(yc);
72  s.setL(l);
73  }
74 
75  s.setAlpha(atan2(y1 - y2, x1 - x2));
76 }
77 
86 void vpFeatureBuilder::create(vpFeatureSegment &s, const vpCameraParameters &cam, const vpDot2 &d1, const vpDot2 &d2)
87 {
88  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
89 
92 
93  double xc = (x1 + x2) / 2.;
94  double yc = (y1 + y2) / 2.;
95  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
96 
97  if (s.isNormalized()) {
98  s.setXc(xc / l);
99  s.setYc(yc / l);
100  s.setL(1 / l);
101  }
102  else {
103  s.setXc(xc);
104  s.setYc(yc);
105  s.setL(l);
106  }
107 
108  s.setAlpha(atan2(y1 - y2, x1 - x2));
109 }
110 #endif //#ifdef VISP_HAVE_MODULE_BLOB
111 
121  const vpImagePoint &ip2)
122 {
123  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
124 
125  vpPixelMeterConversion::convertPoint(cam, ip1, x1, y1);
126  vpPixelMeterConversion::convertPoint(cam, ip2, x2, y2);
127 
128  double xc = (x1 + x2) / 2.;
129  double yc = (y1 + y2) / 2.;
130  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
131 
132  if (s.isNormalized()) {
133  s.setXc(xc / l);
134  s.setYc(yc / l);
135  s.setL(1 / l);
136  }
137  else {
138  s.setXc(xc);
139  s.setYc(yc);
140  s.setL(l);
141  }
142 
143  s.setAlpha(atan2(y1 - y2, x1 - x2));
144 }
145 
155 {
156  double x1 = P1.get_x();
157  double y1 = P1.get_y();
158  double x2 = P2.get_x();
159  double y2 = P2.get_y();
160 
161  double Z1 = P1.cP[2] / P1.cP[3];
162  double Z2 = P2.cP[2] / P2.cP[3];
163 
164  s.buildFrom(x1, y1, Z1, x2, y2, Z2);
165 }
166 END_VISP_NAMESPACE
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:125
vpImagePoint getCog() const
Definition: vpDot2.h:181
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
Definition: vpDot.h:116
vpImagePoint getCog() const
Definition: vpDot.h:247
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
void setAlpha(double val)
void setL(double val)
vpFeatureSegment & buildFrom(const double &x1, const double &y1, const double &Z1, const double &x2, const double &y2, const double &Z2)
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:79
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:422
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:420
vpColVector cP
Definition: vpTracker.h:73