Visual Servoing Platform  version 3.6.1 under development (2024-04-23)
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 #ifdef VISP_HAVE_MODULE_BLOB
43 
52 void vpFeatureBuilder::create(vpFeatureSegment &s, const vpCameraParameters &cam, const vpDot &d1, const vpDot &d2)
53 {
54  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
55 
58 
59  double xc = (x1 + x2) / 2.;
60  double yc = (y1 + y2) / 2.;
61  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
62 
63  if (s.isNormalized()) {
64  s.setXc(xc / l);
65  s.setYc(yc / l);
66  s.setL(1 / l);
67  }
68  else {
69  s.setXc(xc);
70  s.setYc(yc);
71  s.setL(l);
72  }
73 
74  s.setAlpha(atan2(y1 - y2, x1 - x2));
75 }
76 
85 void vpFeatureBuilder::create(vpFeatureSegment &s, const vpCameraParameters &cam, const vpDot2 &d1, const vpDot2 &d2)
86 {
87  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
88 
91 
92  double xc = (x1 + x2) / 2.;
93  double yc = (y1 + y2) / 2.;
94  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
95 
96  if (s.isNormalized()) {
97  s.setXc(xc / l);
98  s.setYc(yc / l);
99  s.setL(1 / l);
100  }
101  else {
102  s.setXc(xc);
103  s.setYc(yc);
104  s.setL(l);
105  }
106 
107  s.setAlpha(atan2(y1 - y2, x1 - x2));
108 }
109 #endif //#ifdef VISP_HAVE_MODULE_BLOB
110 
120  const vpImagePoint &ip2)
121 {
122  double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
123 
124  vpPixelMeterConversion::convertPoint(cam, ip1, x1, y1);
125  vpPixelMeterConversion::convertPoint(cam, ip2, x2, y2);
126 
127  double xc = (x1 + x2) / 2.;
128  double yc = (y1 + y2) / 2.;
129  double l = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
130 
131  if (s.isNormalized()) {
132  s.setXc(xc / l);
133  s.setYc(yc / l);
134  s.setL(1 / l);
135  }
136  else {
137  s.setXc(xc);
138  s.setYc(yc);
139  s.setL(l);
140  }
141 
142  s.setAlpha(atan2(y1 - y2, x1 - x2));
143 }
144 
154 {
155  double x1 = P1.get_x();
156  double y1 = P1.get_y();
157  double x2 = P2.get_x();
158  double y2 = P2.get_y();
159 
160  double Z1 = P1.cP[2] / P1.cP[3];
161  double Z2 = P2.cP[2] / P2.cP[3];
162 
163  s.buildFrom(x1, y1, Z1, x2, y2, Z2);
164 }
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:176
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:242
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:465
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:463
vpColVector cP
Definition: vpTracker.h:71