Visual Servoing Platform  version 3.0.0
vpTemplateTrackerWarpAffine.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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/vpTemplateTrackerWarpAffine.h>
40 
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 
98 
100 {
101  vXres[0]=(1.0+ParamM[0])*vX[0]+ParamM[2]*vX[1]+ParamM[4];
102  vXres[1]=ParamM[1]*vX[0]+(1.0+ParamM[3])*vX[1]+ParamM[5];
103 }
104 
105 void vpTemplateTrackerWarpAffine::dWarp(const vpColVector &X1,const vpColVector &/*X2*/,const vpColVector &/*ParamM*/,vpMatrix &dW_)
106 {
107  double j=X1[0];
108  double i=X1[1];
109  dW_=0;
110  dW_[0][0]=j;dW_[0][2]=i;dW_[0][4]=1;
111  dW_[1][1]=j;dW_[1][3]=i;dW_[1][5]=1;
112 }
113 
114 /*compute dw=dw/dx*dw/dp
115 */
116 void vpTemplateTrackerWarpAffine::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])*dwdp0[i]+ParamM[2]*dwdp0[i+nbParam];
122  dW_[1][i]=ParamM[1]*dwdp0[i]+(1.+ParamM[3])*dwdp0[i+nbParam];
123  }
124 }
125 
127 {
128  vXres[0]=(1+ParamM[0])*vX[0]+ParamM[2]*vX[1]+ParamM[4];
129  vXres[1]=ParamM[1]*vX[0]+(1+ParamM[3])*vX[1]+ParamM[5];
130 }
132 {
133  vpColVector Trans(2);
134  vpMatrix MWrap(2,2);
135  Trans[0]=ParamM[4];Trans[1]=ParamM[5];
136  MWrap[0][0]=1+ParamM[0];MWrap[0][1]=ParamM[2];
137  MWrap[1][0]=ParamM[1];MWrap[1][1]=1+ParamM[3];
138 
139  vpMatrix MWrapInv(2,2);MWrapInv=MWrap.inverseByLU();
140  vpColVector TransInv(2);TransInv=-1*MWrapInv*Trans;
141 
142  ParamMinv[0]=MWrapInv[0][0]-1;ParamMinv[2]=MWrapInv[0][1];
143  ParamMinv[1]=MWrapInv[1][0];ParamMinv[3]=MWrapInv[1][1]-1;
144  ParamMinv[4]=TransInv[0];ParamMinv[5]=TransInv[1];
145 }
146 
148 {
149  vpColVector Trans1(2);
150  vpMatrix MWrap1(2,2);
151  Trans1[0]=p1[4];Trans1[1]=p1[5];
152  MWrap1[0][0]=1+p1[0];MWrap1[0][1]=p1[2];
153  MWrap1[1][0]=p1[1];MWrap1[1][1]=1+p1[3];
154 
155  vpColVector Trans2(2);
156  vpMatrix MWrap2(2,2);
157  Trans2[0]=p2[4];Trans2[1]=p2[5];
158  MWrap2[0][0]=1+p2[0];MWrap2[0][1]=p2[2];
159  MWrap2[1][0]=p2[1];MWrap2[1][1]=1+p2[3];
160 
161  vpColVector TransRes(2);
162  vpMatrix MWrapRes(2,2);
163  TransRes=MWrap1*Trans2+Trans1;
164  MWrapRes=MWrap1*MWrap2;
165 
166  pres[0]=MWrapRes[0][0]-1;pres[2]=MWrapRes[0][1];
167  pres[1]=MWrapRes[1][0];pres[3]=MWrapRes[1][1]-1;
168  pres[4]=TransRes[0];pres[5]=TransRes[1];
169 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
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)