Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpFeatureBuilderEllipse.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  * Conversion between tracker and visual feature ellipse.
33  *
34  * Authors:
35  * Eric Marchand
36  *
37  *****************************************************************************/
38 
45 #include <visp3/core/vpMath.h>
46 #include <visp3/visual_features/vpFeatureBuilder.h>
47 
63 {
64  // 3D data
65  double alpha = t.cP[0]; // A
66  double beta = t.cP[1]; // B
67  double gamma = t.cP[2]; // C
68 
69  double X0 = t.cP[3];
70  double Y0 = t.cP[4];
71  double Z0 = t.cP[5];
72 
73  // equation p 318 prior eq (39)
74  double d = alpha * X0 + beta * Y0 + gamma * Z0;
75 
76  double A = alpha / d;
77  double B = beta / d;
78  double C = gamma / d;
79 
80  s.setABC(A, B, C);
81 
82  // 2D data
83  s.buildFrom(t.p[0], t.p[1], t.p[2], t.p[3], t.p[4]);
84 }
85 
101 {
102  // 3D data
103  double X0 = t.cP[0];
104  double Y0 = t.cP[1];
105  double Z0 = t.cP[2];
106  double R = t.cP[3];
107 
108  double d = vpMath::sqr(X0) + vpMath::sqr(Y0) + vpMath::sqr(Z0) - vpMath::sqr(R);
109 
110  double A = X0 / d;
111  double B = Y0 / d;
112  double C = Z0 / d;
113 
114  s.setABC(A, B, C);
115 
116  // 2D data
117  s.buildFrom(t.p[0], t.p[1], t.p[2], t.p[3], t.p[4]);
118 }
119 
120 #ifdef VISP_HAVE_MODULE_BLOB
121 
139 {
140  double xc = 0, yc = 0;
141  vpPixelMeterConversion::convertPoint(cam, blob.getCog(), xc, yc);
142  vpColVector nij = blob.get_nij();
143 
144  s.buildFrom(xc, yc, nij[0], nij[1], nij[2]);
145 }
146 
165 {
166  double xc = 0, yc = 0;
167  vpPixelMeterConversion::convertPoint(cam, blob.getCog(), xc, yc);
168  vpColVector nij = blob.get_nij();
169 
170  s.buildFrom(xc, yc, nij[0], nij[1], nij[2]);
171 }
172 #endif //#ifdef VISP_HAVE_MODULE_BLOB
173 
174 #ifdef VISP_HAVE_MODULE_ME
175 
193 {
194  double xg, yg, n20, n11, n02;
196  ellipse.get_nij()[0], ellipse.get_nij()[1], ellipse.get_nij()[2],
197  xg, yg, n20, n11, n02);
198 
199  s.buildFrom(xg, yg, n20, n11, n02);
200 }
201 
202 #endif //#ifdef VISP_HAVE_MODULE_ME
void buildFrom(double x, double y, double n20, double n11, double n02)
Class that tracks an ellipse using moving edges.
Definition: vpMeEllipse.h:97
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:82
vpColVector get_nij() const
Definition: vpMeEllipse.h:115
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:126
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)
vpColVector cP
Definition: vpTracker.h:77
vpColVector get_nij() const
Definition: vpDot2.h:148
vpImagePoint getCog() const
Definition: vpDot.h:247
static double sqr(double x)
Definition: vpMath.h:116
Generic class defining intrinsic camera parameters.
void setABC(double A, double B, double C)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
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:180
Class that defines 2D ellipse visual feature.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
vpColVector get_nij() const
Definition: vpDot.h:210
Class that defines a 3D circle in the object frame and allows forward projection of a 3D circle in th...
Definition: vpCircle.h:91
vpImagePoint getCenter() const
Definition: vpMeEllipse.h:159
vpColVector p
Definition: vpTracker.h:73