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