ViSP  2.9.0
vpTemplateTrackerWarpSRT.cpp
1 /****************************************************************************
2  *
3  * $Id: vpTemplateTrackerWarpSRT.cpp 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  * Description:
34  * Template tracker.
35  *
36  * Authors:
37  * Amaury Dame
38  * Aurelien Yol
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 #include <visp/vpTemplateTrackerWarpSRT.h>
43 
44 
46 {
47  nbParam = 4 ;
48  dW.resize(2,nbParam);
49 }
50 
51 //get the parameter corresponding to the lower level of a gaussian pyramid
53 {
54  pdown=p;
55  pdown[2]=p[2]/2.;
56  pdown[3]=p[3]/2.;
57 }
58 
60 {
61  pup=p;
62  pup[2]=p[2]*2.;
63  pup[3]=p[3]*2.;
64 }
65 /*calcul de di*dw(x,p0)/dp
66 */
67 void vpTemplateTrackerWarpSRT::getdW0(const int &i,const int &j,const double &dy,const double &dx,double *dIdW)
68 {
69  // std::cout << "getdW0" << std::endl;
70  dIdW[0]=j*dx + i*dy;
71  dIdW[1]=-i*dx + j*dy;
72  dIdW[2]=dx;
73  dIdW[3]=dy;
74 }
75 /*calcul de dw(x,p0)/dp
76 */
77 void vpTemplateTrackerWarpSRT::getdWdp0(const int &i,const int &j,double *dIdW)
78 {
79  dIdW[0]=j;
80  dIdW[1]=-i;
81  dIdW[2]=1.;
82  dIdW[3]=0;
83 
84  dIdW[4]=i;
85  dIdW[5]=j;
86  dIdW[6]=0;
87  dIdW[7]=1.;
88 }
89 
90 void vpTemplateTrackerWarpSRT::warpX(const int &i,const int &j,double &i2,double &j2,const vpColVector &ParamM)
91 {
92  j2=((1.0+ParamM[0])*cos(ParamM[1])*j) - ((1.0+ParamM[0])*sin(ParamM[1])*i) + ParamM[2];
93  i2=((1.0+ParamM[0])*sin(ParamM[1])*j) + ((1.0+ParamM[0])*cos(ParamM[1])*i) + ParamM[3];
94 }
95 
96 
98 {
99  vXres[0]=((1.0+ParamM[0])*cos(ParamM[1])*vX[0]) - ((1.0+ParamM[0])*sin(ParamM[1])*vX[1]) + ParamM[2];
100  vXres[1]=((1.0+ParamM[0])*sin(ParamM[1])*vX[0]) + ((1.0+ParamM[0])*cos(ParamM[1])*vX[1]) + ParamM[3];
101 }
102 
103 void vpTemplateTrackerWarpSRT::dWarp(const vpColVector &X1,const vpColVector &/*X2*/,const vpColVector &ParamM,vpMatrix &dW_)
104 {
105  double j=X1[0];
106  double i=X1[1];
107  dW_=0;
108  dW_[0][0]=cos(ParamM[1])*j - sin(ParamM[1])*i;
109  dW_[0][1]=(-(1.0+ParamM[0])*sin(ParamM[1])*j) - ((1.0+ParamM[0])*cos(ParamM[1])*i);
110  dW_[0][2]=1;
111 
112  dW_[1][0]=sin(ParamM[1])*j + cos(ParamM[1])*i;
113  dW_[1][1]=(1.0+ParamM[0])*cos(ParamM[1])*j - (1.0+ParamM[0])*sin(ParamM[1])*i;
114  dW_[1][3]=1;
115 }
116 
117 /*compute dw=dw/dx*dw/dp
118 */
119 void vpTemplateTrackerWarpSRT::dWarpCompo(const vpColVector &/*X1*/,const vpColVector &/*X2*/,const vpColVector &ParamM,
120  const double *dwdp0,vpMatrix &dW_)
121 {
122  for(unsigned int i=0;i<nbParam;i++)
123  {
124  dW_[0][i]=((1.+ParamM[0])*cos(ParamM[1])*dwdp0[i]) - ((1.0+ParamM[0])*sin(ParamM[1])*dwdp0[i+nbParam]);
125  dW_[1][i]=((1.+ParamM[0])*sin(ParamM[1])*dwdp0[i]) + ((1.0+ParamM[0])*cos(ParamM[1])*dwdp0[i+nbParam]);
126  }
127 }
128 
130 {
131  // std::cout << "warpXspe" << std::endl;
132  vXres[0]=((1.0+ParamM[0])*cos(ParamM[1])*vX[0]) - ((1.0+ParamM[0])*sin(ParamM[1])*vX[1]) + ParamM[2];
133  vXres[1]=((1.0+ParamM[0])*sin(ParamM[1])*vX[0]) + ((1.0+ParamM[0])*cos(ParamM[1])*vX[1]) + ParamM[3];
134 }
135 
137 {
138  vpColVector Trans(2);
139  vpMatrix MWrap(2,2);
140  Trans[0]=ParamM[2];
141  Trans[1]=ParamM[3];
142  MWrap[0][0]=cos(ParamM[1]);
143  MWrap[0][1]=-sin(ParamM[1]);
144  MWrap[1][0]=sin(ParamM[1]);
145  MWrap[1][1]=cos(ParamM[1]);
146 
147  vpMatrix MWrapInv(2,2);
148  MWrapInv=MWrap.transpose();
149  vpColVector TransInv(2);
150  TransInv=(-1.0/(1.0+ParamM[0]))*MWrapInv*Trans;
151 
152  ParamMinv[0]=1.0/(1.0+ParamM[0]) - 1.0;
153  ParamMinv[1]= atan2(MWrapInv[1][0],MWrapInv[1][1]);
154  ParamMinv[2]=TransInv[0];
155  ParamMinv[3]=TransInv[1];
156 }
157 
159 {
160  vpColVector Trans1(2);
161  vpMatrix MWrap1(2,2);
162  Trans1[0]=p1[2];Trans1[1]=p1[3];
163 
164  MWrap1[0][0]=cos(p1[1]);
165  MWrap1[0][1]=-sin(p1[1]);
166  MWrap1[1][0]=sin(p1[1]);
167  MWrap1[1][1]=cos(p1[1]);
168 
169  vpColVector Trans2(2);
170  vpMatrix MWrap2(2,2);
171  Trans2[0]=p2[2];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 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:183
void pRondp(const vpColVector &p1, const vpColVector &p2, vpColVector &pres) const
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:1255
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)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
void getParamInverse(const vpColVector &ParamM, vpColVector &ParamMinv) const