ViSP  2.9.0
vpTemplateTrackerWarpAffine.cpp
1 /****************************************************************************
2  *
3  * $Id: vpTemplateTrackerWarpAffine.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/vpTemplateTrackerWarpAffine.h>
43 
44 
46 {
47  nbParam = 6 ;
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[4]=p[4]/2.;
56  pdown[5]=p[5]/2.;
57 }
58 
60 {
61  pup=p;
62  pup[4]=p[4]*2.;
63  pup[5]=p[5]*2.;
64 }
65 /*calcul de di*dw(x,p0)/dp
66 */
67 void vpTemplateTrackerWarpAffine::getdW0(const int &i,const int &j,const double &dy,const double &dx,double *dIdW)
68 {
69  dIdW[0]=j*dx;
70  dIdW[1]=j*dy;
71  dIdW[2]=i*dx;
72  dIdW[3]=i*dy;
73  dIdW[4]=dx;
74  dIdW[5]=dy;
75 }
76 /*calcul de dw(x,p0)/dp
77 */
78 void vpTemplateTrackerWarpAffine::getdWdp0(const int &i,const int &j,double *dIdW)
79 {
80  dIdW[0]=j;
81  dIdW[1]=0;
82  dIdW[2]=i;
83  dIdW[3]=0;
84  dIdW[4]=1.;
85  dIdW[5]=0;
86 
87  dIdW[6]=0;
88  dIdW[7]=j;
89  dIdW[8]=0;
90  dIdW[9]=i;
91  dIdW[10]=0;
92  dIdW[11]=1.;
93 }
94 
95 void vpTemplateTrackerWarpAffine::warpX(const int &i, const int &j,double &i2,double &j2, const vpColVector &ParamM)
96 {
97  j2=(1+ParamM[0])*j+ParamM[2]*i+ParamM[4];
98  i2=ParamM[1]*j+(1+ParamM[3])*i+ParamM[5];
99 }
100 
101 
103 {
104  vXres[0]=(1.0+ParamM[0])*vX[0]+ParamM[2]*vX[1]+ParamM[4];
105  vXres[1]=ParamM[1]*vX[0]+(1.0+ParamM[3])*vX[1]+ParamM[5];
106 }
107 
108 void vpTemplateTrackerWarpAffine::dWarp(const vpColVector &X1,const vpColVector &/*X2*/,const vpColVector &/*ParamM*/,vpMatrix &dW_)
109 {
110  double j=X1[0];
111  double i=X1[1];
112  dW_=0;
113  dW_[0][0]=j;dW_[0][2]=i;dW_[0][4]=1;
114  dW_[1][1]=j;dW_[1][3]=i;dW_[1][5]=1;
115 }
116 
117 /*compute dw=dw/dx*dw/dp
118 */
119 void vpTemplateTrackerWarpAffine::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])*dwdp0[i]+ParamM[2]*dwdp0[i+nbParam];
125  dW_[1][i]=ParamM[1]*dwdp0[i]+(1.+ParamM[3])*dwdp0[i+nbParam];
126  }
127 }
128 
130 {
131  vXres[0]=(1+ParamM[0])*vX[0]+ParamM[2]*vX[1]+ParamM[4];
132  vXres[1]=ParamM[1]*vX[0]+(1+ParamM[3])*vX[1]+ParamM[5];
133 }
135 {
136  vpColVector Trans(2);
137  vpMatrix MWrap(2,2);
138  Trans[0]=ParamM[4];Trans[1]=ParamM[5];
139  MWrap[0][0]=1+ParamM[0];MWrap[0][1]=ParamM[2];
140  MWrap[1][0]=ParamM[1];MWrap[1][1]=1+ParamM[3];
141 
142  vpMatrix MWrapInv(2,2);MWrapInv=MWrap.inverseByLU();
143  vpColVector TransInv(2);TransInv=-1*MWrapInv*Trans;
144 
145  ParamMinv[0]=MWrapInv[0][0]-1;ParamMinv[2]=MWrapInv[0][1];
146  ParamMinv[1]=MWrapInv[1][0];ParamMinv[3]=MWrapInv[1][1]-1;
147  ParamMinv[4]=TransInv[0];ParamMinv[5]=TransInv[1];
148 }
149 
151 {
152  vpColVector Trans1(2);
153  vpMatrix MWrap1(2,2);
154  Trans1[0]=p1[4];Trans1[1]=p1[5];
155  MWrap1[0][0]=1+p1[0];MWrap1[0][1]=p1[2];
156  MWrap1[1][0]=p1[1];MWrap1[1][1]=1+p1[3];
157 
158  vpColVector Trans2(2);
159  vpMatrix MWrap2(2,2);
160  Trans2[0]=p2[4];Trans2[1]=p2[5];
161  MWrap2[0][0]=1+p2[0];MWrap2[0][1]=p2[2];
162  MWrap2[1][0]=p2[1];MWrap2[1][1]=1+p2[3];
163 
164  vpColVector TransRes(2);
165  vpMatrix MWrapRes(2,2);
166  TransRes=MWrap1*Trans2+Trans1;
167  MWrapRes=MWrap1*MWrap2;
168 
169  pres[0]=MWrapRes[0][0]-1;pres[2]=MWrapRes[0][1];
170  pres[1]=MWrapRes[1][0];pres[3]=MWrapRes[1][1]-1;
171  pres[4]=TransRes[0];pres[5]=TransRes[1];
172 }
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 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)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
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)