Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpTemplateTrackerWarpSRT.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Template tracker.
32  *
33  * Authors:
34  * Amaury Dame
35  * Aurelien Yol
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 #include <visp3/tt/vpTemplateTrackerWarpSRT.h>
40 
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 
93 
95 {
96  vXres[0]=((1.0+ParamM[0])*cos(ParamM[1])*vX[0]) - ((1.0+ParamM[0])*sin(ParamM[1])*vX[1]) + ParamM[2];
97  vXres[1]=((1.0+ParamM[0])*sin(ParamM[1])*vX[0]) + ((1.0+ParamM[0])*cos(ParamM[1])*vX[1]) + ParamM[3];
98 }
99 
100 void vpTemplateTrackerWarpSRT::dWarp(const vpColVector &X1,const vpColVector &/*X2*/,const vpColVector &ParamM,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 */
116 void vpTemplateTrackerWarpSRT::dWarpCompo(const vpColVector &/*X1*/,const vpColVector &/*X2*/,const vpColVector &ParamM,
117  const double *dwdp0,vpMatrix &dW_)
118 {
119  for(unsigned int i=0;i<nbParam;i++)
120  {
121  dW_[0][i]=((1.+ParamM[0])*cos(ParamM[1])*dwdp0[i]) - ((1.0+ParamM[0])*sin(ParamM[1])*dwdp0[i+nbParam]);
122  dW_[1][i]=((1.+ParamM[0])*sin(ParamM[1])*dwdp0[i]) + ((1.0+ParamM[0])*cos(ParamM[1])*dwdp0[i+nbParam]);
123  }
124 }
125 
127 {
128  // std::cout << "warpXspe" << std::endl;
129  vXres[0]=((1.0+ParamM[0])*cos(ParamM[1])*vX[0]) - ((1.0+ParamM[0])*sin(ParamM[1])*vX[1]) + ParamM[2];
130  vXres[1]=((1.0+ParamM[0])*sin(ParamM[1])*vX[0]) + ((1.0+ParamM[0])*cos(ParamM[1])*vX[1]) + ParamM[3];
131 }
132 
134 {
135  vpColVector Trans(2);
136  vpMatrix MWrap(2,2);
137  Trans[0]=ParamM[2];
138  Trans[1]=ParamM[3];
139  MWrap[0][0]=cos(ParamM[1]);
140  MWrap[0][1]=-sin(ParamM[1]);
141  MWrap[1][0]=sin(ParamM[1]);
142  MWrap[1][1]=cos(ParamM[1]);
143 
144  vpMatrix MWrapInv(2,2);
145  MWrapInv=MWrap.transpose();
146  vpColVector TransInv(2);
147  TransInv=(-1.0/(1.0+ParamM[0]))*MWrapInv*Trans;
148 
149  ParamMinv[0]=1.0/(1.0+ParamM[0]) - 1.0;
150  ParamMinv[1]= atan2(MWrapInv[1][0],MWrapInv[1][1]);
151  ParamMinv[2]=TransInv[0];
152  ParamMinv[3]=TransInv[1];
153 }
154 
156 {
157  vpColVector Trans1(2);
158  vpMatrix MWrap1(2,2);
159  Trans1[0]=p1[2];Trans1[1]=p1[3];
160 
161  MWrap1[0][0]=cos(p1[1]);
162  MWrap1[0][1]=-sin(p1[1]);
163  MWrap1[1][0]=sin(p1[1]);
164  MWrap1[1][1]=cos(p1[1]);
165 
166  vpColVector Trans2(2);
167  vpMatrix MWrap2(2,2);
168  Trans2[0]=p2[2];Trans2[1]=p2[3];
169 
170  MWrap2[0][0]=cos(p2[1]);
171  MWrap2[0][1]=-sin(p2[1]);
172  MWrap2[1][0]=sin(p2[1]);
173  MWrap2[1][1]=cos(p2[1]);
174 
175  vpColVector TransRes(2);
176  vpMatrix MWrapRes(2,2);
177  TransRes=(1.0+p1[0])*MWrap1*Trans2+Trans1;
178  MWrapRes=MWrap1*MWrap2;
179 
180  pres[0]=(1.0+p1[0])*(1.0+p2[0]) - 1.0;
181  pres[1]=atan2(MWrapRes[1][0],MWrapRes[1][1]);
182 
183  pres[2]=TransRes[0];
184  pres[3]=TransRes[1];
185 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
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)
Definition: vpArray2D.h:167
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:233
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:72
void getParamInverse(const vpColVector &ParamM, vpColVector &ParamMinv) const