Visual Servoing Platform  version 3.6.1 under development (2024-11-14)
vpFeatureBuilderEllipse.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  * Conversion between tracker and visual feature ellipse.
33  *
34 *****************************************************************************/
35 
42 #include <visp3/core/vpMath.h>
43 #include <visp3/visual_features/vpFeatureBuilder.h>
44 
45 BEGIN_VISP_NAMESPACE
61 {
62  // 3D data
63  double alpha = t.cP[0]; // A
64  double beta = t.cP[1]; // B
65  double gamma = t.cP[2]; // C
66 
67  double X0 = t.cP[3];
68  double Y0 = t.cP[4];
69  double Z0 = t.cP[5];
70 
71  // equation p 318 prior eq (39)
72  double d = alpha * X0 + beta * Y0 + gamma * Z0;
73 
74  double A = alpha / d;
75  double B = beta / d;
76  double C = gamma / d;
77 
78  s.setABC(A, B, C);
79 
80  // 2D data
81  s.buildFrom(t.p[0], t.p[1], t.p[2], t.p[3], t.p[4]);
82 }
83 
99 {
100  // 3D data
101  double X0 = t.cP[0];
102  double Y0 = t.cP[1];
103  double Z0 = t.cP[2];
104  double R = t.cP[3];
105 
106  double d = vpMath::sqr(X0) + vpMath::sqr(Y0) + vpMath::sqr(Z0) - vpMath::sqr(R);
107 
108  double A = X0 / d;
109  double B = Y0 / d;
110  double C = Z0 / d;
111 
112  s.setABC(A, B, C);
113 
114  // 2D data
115  s.buildFrom(t.p[0], t.p[1], t.p[2], t.p[3], t.p[4]);
116 }
117 
118 #ifdef VISP_HAVE_MODULE_BLOB
136 void vpFeatureBuilder::create(vpFeatureEllipse &s, const vpCameraParameters &cam, const vpDot &blob)
137 {
138  double xc = 0, yc = 0;
139  vpPixelMeterConversion::convertPoint(cam, blob.getCog(), xc, yc);
140  vpColVector nij = blob.get_nij();
141 
142  s.buildFrom(xc, yc, nij[0], nij[1], nij[2]);
143 }
144 
162 void vpFeatureBuilder::create(vpFeatureEllipse &s, const vpCameraParameters &cam, const vpDot2 &blob)
163 {
164  double xc = 0, yc = 0;
165  vpPixelMeterConversion::convertPoint(cam, blob.getCog(), xc, yc);
166  vpColVector nij = blob.get_nij();
167 
168  s.buildFrom(xc, yc, nij[0], nij[1], nij[2]);
169 }
170 #endif //#ifdef VISP_HAVE_MODULE_BLOB
171 
172 #ifdef VISP_HAVE_MODULE_ME
190 void vpFeatureBuilder::create(vpFeatureEllipse &s, const vpCameraParameters &cam, const vpMeEllipse &ellipse)
191 {
192  double xg, yg, n20, n11, n02;
193  vpPixelMeterConversion::convertEllipse(cam, ellipse.getCenter(), ellipse.get_nij()[0], ellipse.get_nij()[1],
194  ellipse.get_nij()[2], xg, yg, n20, n11, n02);
195 
196  s.buildFrom(xg, yg, n20, n11, n02);
197 }
198 
199 #endif //#ifdef VISP_HAVE_MODULE_ME
200 END_VISP_NAMESPACE
Generic class defining intrinsic camera parameters.
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
Definition: vpCircle.h:87
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
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
vpColVector get_nij() const
Definition: vpDot2.h:145
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage.
Definition: vpDot.h:116
vpColVector get_nij() const
Definition: vpDot.h:209
vpImagePoint getCog() const
Definition: vpDot.h:247
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Class that defines 2D ellipse visual feature.
vpFeatureEllipse & buildFrom(const double &x, const double &y, const double &n20, const double &n11, const double &n02)
void setABC(double A, double B, double C)
static double sqr(double x)
Definition: vpMath.h:203
Class that tracks an ellipse using moving edges.
Definition: vpMeEllipse.h:96
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:184
vpColVector get_nij() const
Definition: vpMeEllipse.h:134
static void convertEllipse(const vpCameraParameters &cam, const vpImagePoint &center_p, double n20_p, double n11_p, double n02_p, double &xc_m, double &yc_m, double &n20_m, double &n11_m, double &n02_m)
static void convertPoint(const vpCameraParameters &cam, const double &u, const double &v, double &x, double &y)
Class that defines a 3D sphere in the object frame and allows forward projection of a 3D sphere in th...
Definition: vpSphere.h:80
vpColVector cP
Definition: vpTracker.h:73
vpColVector p
Definition: vpTracker.h:69