Visual Servoing Platform  version 3.0.0
vpTemplateTrackerSSD.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 
40 #include <visp3/tt/vpTemplateTrackerSSD.h>
41 
43  : vpTemplateTracker(warp), DI(), temp()
44 {
45  dW.resize(2,nbParam);
46  G.resize(nbParam);
49 
51 
52  X1.resize(2);
53  X2.resize(2);
54  DI.resize(2);
55 }
56 
58 {
59  double erreur=0;
60  double IW,Tij;
61  int i,j;
62  double i2,j2;
63  int Nbpoint=0;
64 
65  Warp->computeCoeff(tp);
66  for(unsigned int point=0;point<templateSize;point++)
67  {
68  i=ptTemplate[point].y;
69  j=ptTemplate[point].x;
70  X1[0]=j;X1[1]=i;
71  Warp->computeDenom(X1,tp);
72  Warp->warpX(X1,X2,tp);
73 
74  j2=X2[0];i2=X2[1];
75  if((i2>=0)&&(j2>=0)&&(i2<I.getHeight()-1)&&(j2<I.getWidth()-1))
76  {
77  Tij=ptTemplate[point].val;
78  if(!blur)
79  IW=I.getValue(i2,j2);
80  else
81  IW=BI.getValue(i2,j2);
82  //IW=getSubPixBspline4(I,i2,j2);
83  erreur+=((double)Tij-IW)*((double)Tij-IW);
84  Nbpoint++;
85  }
86  }
87  ratioPixelIn=(double)Nbpoint/(double)templateSize;
88 
89  if(Nbpoint==0)return 10e10;
90  return erreur/Nbpoint;
91 }
92 
93 
95 {
96  double erreur=0;
97  double IW,Tij;
98  int i,j;
99  double i2,j2;
100  unsigned int Nbpoint=0;
101 
102  if(pyrInitialised)
103  {
106  }
107 
108  Warp->computeCoeff(tp);
109  for(unsigned int point=0;point<templateSize;point++)
110  {
111  i=ptTemplate[point].y;
112  j=ptTemplate[point].x;
113  X1[0]=j;X1[1]=i;
114  Warp->computeDenom(X1,tp);
115  Warp->warpX(X1,X2,tp);
116 
117  j2=X2[0];i2=X2[1];
118  if((j2<I.getWidth()-1)&&(i2<I.getHeight()-1)&&(i2>0)&&(j2>0))
119  {
120  Tij=ptTemplate[point].val;
121  IW=I.getValue(i2,j2);
122  //IW=getSubPixBspline4(I,i2,j2);
123  erreur+=((double)Tij-IW)*((double)Tij-IW);
124  Nbpoint++;
125  }
126  }
127  if(Nbpoint==0)return 10e10;
128  return erreur/Nbpoint;
129 }
unsigned int getWidth() const
Definition: vpImage.h:161
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
vpTemplateTrackerPoint * ptTemplate
vpTemplateTrackerPoint ** ptTemplatePyr
virtual void warpX(const int &i, const int &j, double &i2, double &j2, const vpColVector &ParamM)=0
Type getValue(double i, double j) const
Definition: vpImage.h:1148
vpImage< double > BI
unsigned int templateSize
double getCost(const vpImage< unsigned char > &I, const vpColVector &tp)
double getSSD(const vpImage< unsigned char > &I, const vpColVector &tp)
vpTemplateTrackerSSD(vpTemplateTrackerWarp *warp)
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpRowVector.h:199
unsigned int * templateSizePyr
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
unsigned int getHeight() const
Definition: vpImage.h:152
vpTemplateTrackerWarp * Warp
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:217