Visual Servoing Platform  version 3.3.1 under development (2020-10-22)
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  unsigned int order = 3;
141  vpMatrix mp(order, order);
142  mp = 0;
143  vpMatrix m(order, order);
144  m = 0;
145 
146  mp[0][0] = t.m00;
147  mp[1][0] = t.m10;
148  mp[0][1] = t.m01;
149  mp[2][0] = t.m20;
150  mp[1][1] = t.m11;
151  mp[0][2] = t.m02;
152 
153  vpPixelMeterConversion::convertMoment(cam, order, mp, m);
154 
155  double m00 = m[0][0];
156  double m01 = m[0][1];
157  double m10 = m[1][0];
158  double m02 = m[0][2];
159  double m11 = m[1][1];
160  double m20 = m[2][0];
161 
162  // Chaumette, Image Moments: A General and Useful Set of Features for Visual Servoing, TRO 2004, eq. 14
163  double xc = m10 / m00;
164  double yc = m01 / m00;
165 
166  // Chaumette, Image Moments: A General and Useful Set of Features for Visual Servoing, TRO 2004, eq. 15
167  double n20 = (m20 - m00 * vpMath::sqr(xc)) / (m00);
168  double n02 = (m02 - m00 * vpMath::sqr(yc)) / (m00);
169  double n11 = (m11 - m00 * xc * yc) / (m00);
170 
171  s.buildFrom(xc, yc, n20, n11, n02);
172 }
173 
192 {
193  unsigned int order = 3;
194  vpMatrix mp(order, order);
195  mp = 0;
196  vpMatrix m(order, order);
197  m = 0;
198 
199  mp[0][0] = t.m00;
200  mp[1][0] = t.m10;
201  mp[0][1] = t.m01;
202  mp[2][0] = t.m20;
203  mp[1][1] = t.m11;
204  mp[0][2] = t.m02;
205 
206  vpPixelMeterConversion::convertMoment(cam, order, mp, m);
207 
208  double m00 = m[0][0];
209  double m01 = m[0][1];
210  double m10 = m[1][0];
211  double m02 = m[0][2];
212  double m11 = m[1][1];
213  double m20 = m[2][0];
214 
215  // Chaumette, Image Moments: A General and Useful Set of Features for Visual Servoing, TRO 2004, eq. 14
216  double xc = m10 / m00;
217  double yc = m01 / m00;
218 
219  // Chaumette, Image Moments: A General and Useful Set of Features for Visual Servoing, TRO 2004, eq. 15
220  double n20 = (m20 - m00 * vpMath::sqr(xc)) / (m00);
221  double n02 = (m02 - m00 * vpMath::sqr(yc)) / (m00);
222  double n11 = (m11 - m00 * xc * yc) / (m00);
223 
224  s.buildFrom(xc, yc, n20, n11, n02);
225 }
226 #endif //#ifdef VISP_HAVE_MODULE_BLOB
227 
228 #ifdef VISP_HAVE_MODULE_ME
229 
247 {
248 
249  // modif FC : creer un vpPixelMeterConversion::convertEllipse serait le mieux
250  // mais il faudrait ensuite passer du repere (u,v) au repere (i,j)
251  double xg = 0, yg = 0;
252  vpImagePoint xg_p = t.getCenter();
253  vpPixelMeterConversion::convertPoint(cam, xg_p, xg, yg);
254  // From (i,j) frame to (x,y) frame: mu_20 and mu_02 permuted
255  double mu_02 = t.get_mu20() / vpMath::sqr(cam.get_py());
256  double mu_11 = t.get_mu11() /(cam.get_px() * cam.get_py());
257  double mu_20 = t.get_mu02() / vpMath::sqr(cam.get_px());
258 
259  double n20 = mu_20 / t.get_m00() ;
260  double n11 = mu_11 / t.get_m00() ;
261  double n02 = mu_02 / t.get_m00() ;
262 
263  s.buildFrom(xg, yg, n20, n11, n02);
264 }
265 
266 #endif //#ifdef VISP_HAVE_MODULE_ME
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:156
double m02
Definition: vpDot2.h:392
void buildFrom(double x, double y, double n20, double n11, double n02)
double get_m00() const
Definition: vpMeEllipse.h:146
double m10
Definition: vpDot.h:144
double m00
Definition: vpDot.h:130
Class that tracks an ellipse moving edges.
Definition: vpMeEllipse.h:106
double m11
Definition: vpDot2.h:376
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:83
This tracker is meant to track a blob (connex pixels with same gray level) on a vpImage.
Definition: vpDot2.h:126
double m01
Definition: vpDot2.h:368
double m20
Definition: vpDot.h:158
double m11
Definition: vpDot.h:151
vpColVector cP
Definition: vpTracker.h:77
double m01
Definition: vpDot.h:137
double m20
Definition: vpDot2.h:383
static double sqr(double x)
Definition: vpMath.h:116
double get_mu02() const
Definition: vpMeEllipse.h:200
Generic class defining intrinsic camera parameters.
double get_mu11() const
Definition: vpMeEllipse.h:193
void setABC(double A, double B, double C)
double m02
Definition: vpDot.h:165
static void convertMoment(const vpCameraParameters &cam, unsigned int order, const vpMatrix &moment_pixel, vpMatrix &moment_meter)
double get_mu20() const
Definition: vpMeEllipse.h:207
This tracker is meant to track a dot (connected pixels with same gray level) on a vpImage...
Definition: vpDot.h:115
double m10
Definition: vpDot2.h:360
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
double m00
Definition: vpDot2.h:352
Class that defines 2D ellipse visual feature.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
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:212
vpColVector p
Definition: vpTracker.h:73