Visual Servoing Platform  version 3.5.1 under development (2022-08-17)
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 
54 {
55  p_down[0] = p[0];
56  p_down[1] = p[1];
57  p_down[2] = p[2];
58  p_down[3] = p[3];
59  p_down[4] = p[4] / 2.;
60  p_down[5] = p[5] / 2.;
61 }
62 
70 {
71  p_up[0] = p[0];
72  p_up[1] = p[1];
73  p_up[2] = p[2];
74  p_up[3] = p[3];
75  p_up[4] = p[4] * 2.;
76  p_up[5] = p[5] * 2.;
77 }
78 
87 void vpTemplateTrackerWarpAffine::getdW0(const int &v, const int &u, const double &dv, const double &du, double *dIdW)
88 {
89  dIdW[0] = u * du;
90  dIdW[1] = u * dv;
91  dIdW[2] = v * du;
92  dIdW[3] = v * dv;
93  dIdW[4] = du;
94  dIdW[5] = dv;
95 }
96 
108 void vpTemplateTrackerWarpAffine::getdWdp0(const int &v, const int &u, double *dIdW)
109 {
110  dIdW[0] = u;
111  dIdW[1] = 0;
112  dIdW[2] = v;
113  dIdW[3] = 0;
114  dIdW[4] = 1.;
115  dIdW[5] = 0;
116 
117  dIdW[6] = 0;
118  dIdW[7] = u;
119  dIdW[8] = 0;
120  dIdW[9] = v;
121  dIdW[10] = 0;
122  dIdW[11] = 1.;
123 }
124 
134 void vpTemplateTrackerWarpAffine::warpX(const int &v1, const int &u1, double &v2, double &u2, const vpColVector &p)
135 {
136  u2 = (1 + p[0]) * u1 + p[2] * v1 + p[4];
137  v2 = p[1] * u1 + (1 + p[3]) * v1 + p[5];
138 }
139 
148 {
149  X2[0] = (1.0 + p[0]) * X1[0] + p[2] * X1[1] + p[4];
150  X2[1] = p[1] * X1[0] + (1.0 + p[3]) * X1[1] + p[5];
151 }
152 
163 {
164  double u = X[0];
165  double v = X[1];
166 
167  dM[0][0] = u;
168  dM[0][1] = 0;
169  dM[0][2] = v;
170  dM[0][3] = 0;
171  dM[0][4] = 1;
172  dM[0][5] = 0;
173  dM[1][0] = 0;
174  dM[1][1] = u;
175  dM[1][2] = 0;
176  dM[1][3] = v;
177  dM[1][4] = 0;
178  dM[1][5] = 1;
179 }
180 
189  const double *dwdp0, vpMatrix &dM)
190 {
191  for (unsigned int i = 0; i < nbParam; i++) {
192  dM[0][i] = (1. + p[0]) * dwdp0[i] + p[2] * dwdp0[i + nbParam];
193  dM[1][i] = p[1] * dwdp0[i] + (1. + p[3]) * dwdp0[i + nbParam];
194  }
195 }
196 
205 {
206  X2[0] = (1 + p[0]) * X1[0] + p[2] * X1[1] + p[4];
207  X2[1] = p[1] * X1[0] + (1 + p[3]) * X1[1] + p[5];
208 }
209 
217 {
218  double u = p[4];
219  double v = p[5];
220  double r_00 = 1 + p[0], r_01 = p[2];
221  double r_10 = p[1], r_11 = 1 + p[3];
222  double det = r_00 * r_11 - r_01 * r_10;
223  if (std::fabs(det) < std::numeric_limits<double>::epsilon()) {
224  throw(vpException(vpException::fatalError, "In vpTemplateTrackerWarpAffine::getParamInverse() "
225  "cannot inverse 2-by-2 matrix. Matrix determinant is 0."));
226  }
227 
228  double ri_11 = r_00 / det;
229  double ri_00 = r_11 / det;
230  double ri_01 = -r_01 / det;
231  double ri_10 = -r_10 / det;
232 
233  p_inv[0] = ri_00 - 1;
234  p_inv[1] = ri_10;
235  p_inv[2] = ri_01;
236  p_inv[3] = ri_11 - 1;
237  p_inv[4] = -(ri_00 * u + ri_01 * v);
238  p_inv[5] = -(ri_10 * u + ri_11 * v);
239 }
240 
250 {
251  double r1_00 = 1 + p1[0], r1_01 = p1[2];
252  double r1_10 = p1[1], r1_11 = 1 + p1[3];
253  double r2_00 = 1 + p2[0], r2_01 = p2[2];
254  double r2_10 = p2[1], r2_11 = 1 + p2[3];
255  double u1 = p1[4];
256  double v1 = p1[5];
257  double u2 = p2[4];
258  double v2 = p2[5];
259 
260  p12[0] = r1_00 * r2_00 + r1_01 * r2_10 - 1.;
261  p12[1] = r1_10 * r2_00 + r1_11 * r2_10;
262  p12[2] = r1_00 * r2_01 + r1_01 * r2_11;
263  p12[3] = r1_10 * r2_01 + r1_11 * r2_11 - 1.;
264  p12[4] = r1_00 * u2 + r1_01 * v2 + u1;
265  p12[5] = r1_10 * u2 + r1_11 * v2 + v1;
266 }
void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &p12) const
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:153
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.