Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpTemplateTrackerWarpRT.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/vpTemplateTrackerWarpRT.h>
40 
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 
92 {
93  vXres[0]=(cos(ParamM[0])*vX[0]) - (sin(ParamM[0])*vX[1]) + ParamM[1];
94  vXres[1]=(sin(ParamM[0])*vX[0]) + (cos(ParamM[0])*vX[1]) + ParamM[2];
95 }
96 
97 void vpTemplateTrackerWarpRT::dWarp(const vpColVector &X1,const vpColVector &/*X2*/,const vpColVector &ParamM,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*/,const vpColVector &ParamM,
112  const double *dwdp0,vpMatrix &dW_)
113 {
114  for(unsigned int i=0;i<nbParam;i++)
115  {
116  dW_[0][i]=(cos(ParamM[0])*dwdp0[i]) - (sin(ParamM[0])*dwdp0[i+nbParam]);
117  dW_[1][i]=(sin(ParamM[0])*dwdp0[i]) + (cos(ParamM[0])*dwdp0[i+nbParam]);
118  }
119 }
120 
122 {
123  // std::cout << "warpXspe" << std::endl;
124  vXres[0]=(cos(ParamM[0])*vX[0]) - (sin(ParamM[0])*vX[1]) + ParamM[1];
125  vXres[1]=(sin(ParamM[0])*vX[0]) + (cos(ParamM[0])*vX[1]) + ParamM[2];
126 }
127 
129 {
130  vpColVector Trans(2);
131  vpMatrix MWrap(2,2);
132  Trans[0]=ParamM[1];
133  Trans[1]=ParamM[2];
134  MWrap[0][0]=cos(ParamM[0]);
135  MWrap[0][1]=-sin(ParamM[0]);
136  MWrap[1][0]=sin(ParamM[0]);
137  MWrap[1][1]=cos(ParamM[0]);
138 
139  vpMatrix MWrapInv(2,2);
140  MWrapInv=MWrap.transpose();
141  vpColVector TransInv(2);
142  TransInv=(-1.0)*MWrapInv*Trans;
143 
144  ParamMinv[0]= atan2(MWrapInv[1][0],MWrapInv[1][1]);
145  ParamMinv[1]=TransInv[0];
146  ParamMinv[2]=TransInv[1];
147 }
148 
150 {
151  vpColVector Trans1(2);
152  vpMatrix MWrap1(2,2);
153  Trans1[0]=p1[1];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];Trans2[1]=p2[1];
163 
164  MWrap2[0][0]=cos(p2[0]);
165  MWrap2[0][1]=-sin(p2[0]);
166  MWrap2[1][0]=sin(p2[0]);
167  MWrap2[1][1]=cos(p2[0]);
168 
169  vpColVector TransRes(2);
170  vpMatrix MWrapRes(2,2);
171  TransRes=MWrap1*Trans2+Trans1;
172  MWrapRes=MWrap1*MWrap2;
173 
174  pres[0]=atan2(MWrapRes[1][0],MWrapRes[1][1]);
175  pres[1]=TransRes[0];
176  pres[2]=TransRes[1];
177 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
void warpX(const vpColVector &vX, vpColVector &vXres, const vpColVector &ParamM)
void getdWdp0(const int &i, const int &j, double *dIdW)
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
void getdW0(const int &i, const int &j, const double &dy, const double &dx, 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)
void dWarpCompo(const vpColVector &X1, const vpColVector &X2, const vpColVector &ParamM, const double *dwdp0, vpMatrix &dW)
vpMatrix transpose() const
Definition: vpMatrix.cpp:233
void warpXInv(const vpColVector &vX, vpColVector &vXres, const vpColVector &ParamM)
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:72
void getParamInverse(const vpColVector &ParamM, vpColVector &ParamMinv) const