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