Visual Servoing Platform  version 3.2.0 under development (2019-01-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 
43 {
44  nbParam = 6;
45  dW.resize(2, nbParam);
46 }
47 
48 // get the parameter corresponding to the lower level of a gaussian pyramid
50 {
51  pdown = p;
52  pdown[4] = p[4] / 2.;
53  pdown[5] = p[5] / 2.;
54 }
55 
57 {
58  pup = p;
59  pup[4] = p[4] * 2.;
60  pup[5] = p[5] * 2.;
61 }
62 /*calcul de di*dw(x,p0)/dp
63  */
64 void vpTemplateTrackerWarpAffine::getdW0(const int &i, const int &j, const double &dy, const double &dx, double *dIdW)
65 {
66  dIdW[0] = j * dx;
67  dIdW[1] = j * dy;
68  dIdW[2] = i * dx;
69  dIdW[3] = i * dy;
70  dIdW[4] = dx;
71  dIdW[5] = dy;
72 }
73 /*calcul de dw(x,p0)/dp
74  */
75 void vpTemplateTrackerWarpAffine::getdWdp0(const int &i, const int &j, double *dIdW)
76 {
77  dIdW[0] = j;
78  dIdW[1] = 0;
79  dIdW[2] = i;
80  dIdW[3] = 0;
81  dIdW[4] = 1.;
82  dIdW[5] = 0;
83 
84  dIdW[6] = 0;
85  dIdW[7] = j;
86  dIdW[8] = 0;
87  dIdW[9] = i;
88  dIdW[10] = 0;
89  dIdW[11] = 1.;
90 }
91 
92 void vpTemplateTrackerWarpAffine::warpX(const int &i, const int &j, double &i2, double &j2, const vpColVector &ParamM)
93 {
94  j2 = (1 + ParamM[0]) * j + ParamM[2] * i + ParamM[4];
95  i2 = ParamM[1] * j + (1 + ParamM[3]) * i + ParamM[5];
96 }
97 
99 {
100  vXres[0] = (1.0 + ParamM[0]) * vX[0] + ParamM[2] * vX[1] + ParamM[4];
101  vXres[1] = ParamM[1] * vX[0] + (1.0 + ParamM[3]) * vX[1] + ParamM[5];
102 }
103 
105  const vpColVector & /*ParamM*/, vpMatrix &dW_)
106 {
107  double j = X1[0];
108  double i = X1[1];
109  dW_ = 0;
110  dW_[0][0] = j;
111  dW_[0][2] = i;
112  dW_[0][4] = 1;
113  dW_[1][1] = j;
114  dW_[1][3] = i;
115  dW_[1][5] = 1;
116 }
117 
118 /*compute dw=dw/dx*dw/dp
119  */
121  const vpColVector &ParamM, const double *dwdp0, vpMatrix &dW_)
122 {
123  for (unsigned int i = 0; i < nbParam; i++) {
124  dW_[0][i] = (1. + ParamM[0]) * dwdp0[i] + ParamM[2] * dwdp0[i + nbParam];
125  dW_[1][i] = ParamM[1] * dwdp0[i] + (1. + ParamM[3]) * dwdp0[i + nbParam];
126  }
127 }
128 
130 {
131  vXres[0] = (1 + ParamM[0]) * vX[0] + ParamM[2] * vX[1] + ParamM[4];
132  vXres[1] = ParamM[1] * vX[0] + (1 + ParamM[3]) * vX[1] + ParamM[5];
133 }
135 {
136  vpColVector Trans(2);
137  vpMatrix MWrap(2, 2);
138  Trans[0] = ParamM[4];
139  Trans[1] = ParamM[5];
140  MWrap[0][0] = 1 + ParamM[0];
141  MWrap[0][1] = ParamM[2];
142  MWrap[1][0] = ParamM[1];
143  MWrap[1][1] = 1 + ParamM[3];
144 
145  vpMatrix MWrapInv(2, 2);
146  MWrapInv = MWrap.inverseByLU();
147  vpColVector TransInv(2);
148  TransInv = -1 * MWrapInv * Trans;
149 
150  ParamMinv[0] = MWrapInv[0][0] - 1;
151  ParamMinv[2] = MWrapInv[0][1];
152  ParamMinv[1] = MWrapInv[1][0];
153  ParamMinv[3] = MWrapInv[1][1] - 1;
154  ParamMinv[4] = TransInv[0];
155  ParamMinv[5] = TransInv[1];
156 }
157 
159 {
160  vpColVector Trans1(2);
161  vpMatrix MWrap1(2, 2);
162  Trans1[0] = p1[4];
163  Trans1[1] = p1[5];
164  MWrap1[0][0] = 1 + p1[0];
165  MWrap1[0][1] = p1[2];
166  MWrap1[1][0] = p1[1];
167  MWrap1[1][1] = 1 + p1[3];
168 
169  vpColVector Trans2(2);
170  vpMatrix MWrap2(2, 2);
171  Trans2[0] = p2[4];
172  Trans2[1] = p2[5];
173  MWrap2[0][0] = 1 + p2[0];
174  MWrap2[0][1] = p2[2];
175  MWrap2[1][0] = p2[1];
176  MWrap2[1][1] = 1 + p2[3];
177 
178  vpColVector TransRes(2);
179  vpMatrix MWrapRes(2, 2);
180  TransRes = MWrap1 * Trans2 + Trans1;
181  MWrapRes = MWrap1 * MWrap2;
182 
183  pres[0] = MWrapRes[0][0] - 1;
184  pres[2] = MWrapRes[0][1];
185  pres[1] = MWrapRes[1][0];
186  pres[3] = MWrapRes[1][1] - 1;
187  pres[4] = TransRes[0];
188  pres[5] = TransRes[1];
189 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
Definition: vpArray2D.h:171
void getParamPyramidUp(const vpColVector &p, vpColVector &pup)
void getParamPyramidDown(const vpColVector &p, vpColVector &pdown)
void getParamInverse(const vpColVector &ParamM, vpColVector &ParamMinv) const
void getdW0(const int &i, const int &j, const double &dy, const double &dx, double *dIdW)
void getdWdp0(const int &i, const int &j, double *dIdW)
void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &pres) const
void dWarp(const vpColVector &X1, const vpColVector &X2, const vpColVector &ParamM, vpMatrix &dW)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
vpMatrix inverseByLU() const
void warpXInv(const vpColVector &vX, vpColVector &vXres, const vpColVector &ParamM)
void warpX(const vpColVector &vX, vpColVector &vXres, const vpColVector &ParamM)
void dWarpCompo(const vpColVector &X1, const vpColVector &X2, const vpColVector &ParamM, const double *dwdp0, vpMatrix &dW)