Visual Servoing Platform  version 3.3.1 under development (2020-10-22)
vpTemplateTrackerWarpAffine.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  * Template tracker.
33  *
34  * Authors:
35  * Amaury Dame
36  * Aurelien Yol
37  * Fabien Spindler
38  *
39  *****************************************************************************/
40 #include <visp3/tt/vpTemplateTrackerWarpAffine.h>
41 
46 {
47  nbParam = 6;
48 }
49 
57 {
58  p_down[0] = p[0];
59  p_down[1] = p[1];
60  p_down[2] = p[2];
61  p_down[3] = p[3];
62  p_down[4] = p[4] / 2.;
63  p_down[5] = p[5] / 2.;
64 }
65 
73 {
74  p_up[0] = p[0];
75  p_up[1] = p[1];
76  p_up[2] = p[2];
77  p_up[3] = p[3];
78  p_up[4] = p[4] * 2.;
79  p_up[5] = p[5] * 2.;
80 }
81 
90 void vpTemplateTrackerWarpAffine::getdW0(const int &v, const int &u, const double &dv, const double &du, double *dIdW)
91 {
92  dIdW[0] = u * du;
93  dIdW[1] = u * dv;
94  dIdW[2] = v * du;
95  dIdW[3] = v * dv;
96  dIdW[4] = du;
97  dIdW[5] = dv;
98 }
99 
111 void vpTemplateTrackerWarpAffine::getdWdp0(const int &v, const int &u, double *dIdW)
112 {
113  dIdW[0] = u;
114  dIdW[1] = 0;
115  dIdW[2] = v;
116  dIdW[3] = 0;
117  dIdW[4] = 1.;
118  dIdW[5] = 0;
119 
120  dIdW[6] = 0;
121  dIdW[7] = u;
122  dIdW[8] = 0;
123  dIdW[9] = v;
124  dIdW[10] = 0;
125  dIdW[11] = 1.;
126 }
127 
137 void vpTemplateTrackerWarpAffine::warpX(const int &v1, const int &u1, double &v2, double &u2, const vpColVector &p)
138 {
139  u2 = (1 + p[0]) * u1 + p[2] * v1 + p[4];
140  v2 = p[1] * u1 + (1 + p[3]) * v1 + p[5];
141 }
142 
151 {
152  X2[0] = (1.0 + p[0]) * X1[0] + p[2] * X1[1] + p[4];
153  X2[1] = p[1] * X1[0] + (1.0 + p[3]) * X1[1] + p[5];
154 }
155 
166 {
167  double u = X[0];
168  double v = X[1];
169 
170  dM[0][0] = u;
171  dM[0][1] = 0;
172  dM[0][2] = v;
173  dM[0][3] = 0;
174  dM[0][4] = 1;
175  dM[0][5] = 0;
176  dM[1][0] = 0;
177  dM[1][1] = u;
178  dM[1][2] = 0;
179  dM[1][3] = v;
180  dM[1][4] = 0;
181  dM[1][5] = 1;
182 }
183 
192  const vpColVector &p, const double *dwdp0, vpMatrix &dM)
193 {
194  for (unsigned int i = 0; i < nbParam; i++) {
195  dM[0][i] = (1. + p[0]) * dwdp0[i] + p[2] * dwdp0[i + nbParam];
196  dM[1][i] = p[1] * dwdp0[i] + (1. + p[3]) * dwdp0[i + nbParam];
197  }
198 }
199 
208 {
209  X2[0] = (1 + p[0]) * X1[0] + p[2] * X1[1] + p[4];
210  X2[1] = p[1] * X1[0] + (1 + p[3]) * X1[1] + p[5];
211 }
212 
220 {
221  double u = p[4];
222  double v = p[5];
223  double r_00 = 1 + p[0], r_01 = p[2];
224  double r_10 = p[1], r_11 = 1 + p[3];
225  double det = r_00 * r_11 - r_01 * r_10;
226  if (std::fabs(det) < std::numeric_limits<double>::epsilon()) {
228  "In vpTemplateTrackerWarpAffine::getParamInverse() "
229  "cannot inverse 2-by-2 matrix. Matrix determinant is 0."));
230  }
231 
232  double ri_11 = r_00 / det;
233  double ri_00 = r_11 / det;
234  double ri_01 = -r_01 / det;
235  double ri_10 = -r_10 / det;
236 
237  p_inv[0] = ri_00 - 1;
238  p_inv[1] = ri_10;
239  p_inv[2] = ri_01;
240  p_inv[3] = ri_11 - 1;
241  p_inv[4] = -(ri_00 * u + ri_01 * v);
242  p_inv[5] = -(ri_10 * u + ri_11 * v);
243 }
244 
254 {
255  double r1_00 = 1 + p1[0], r1_01 = p1[2];
256  double r1_10 = p1[1], r1_11 = 1 + p1[3];
257  double r2_00 = 1 + p2[0], r2_01 = p2[2];
258  double r2_10 = p2[1], r2_11 = 1 + p2[3];
259  double u1 = p1[4];
260  double v1 = p1[5];
261  double u2 = p2[4];
262  double v2 = p2[5];
263 
264  p12[0] = r1_00 * r2_00 + r1_01 * r2_10 - 1.;
265  p12[1] = r1_10 * r2_00 + r1_11 * r2_10;
266  p12[2] = r1_00 * r2_01 + r1_01 * r2_11;
267  p12[3] = r1_10 * r2_01 + r1_11 * r2_11 - 1.;
268  p12[4] = r1_00 * u2 + r1_01 * v2 + u1;
269  p12[5] = r1_10 * u2 + r1_11 * v2 + v1;
270 }
void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &p12) const
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:156
void getParamPyramidDown(const vpColVector &p, vpColVector &p_down)
error that can be emited by ViSP classes.
Definition: vpException.h:71
void warpXInv(const vpColVector &X1, vpColVector &X2, const vpColVector &p)
void warpX(const vpColVector &X1, vpColVector &X2, const vpColVector &p)
void dWarp(const vpColVector &X, const vpColVector &, const vpColVector &, vpMatrix &dM)
void dWarpCompo(const vpColVector &, const vpColVector &, const vpColVector &p, const double *dwdp0, vpMatrix &dM)
void getdW0(const int &v, const int &u, const double &dv, const double &du, double *dIdW)
void getParamPyramidUp(const vpColVector &p, vpColVector &p_up)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
void getdWdp0(const int &v, const int &u, double *dIdW)
void getParamInverse(const vpColVector &p, vpColVector &p_inv) const
unsigned int nbParam
Number of parameters used to model warp transformation.