ViSP  2.9.0
vpTemplateTrackerSSD.cpp
1 /****************************************************************************
2  *
3  * $Id: vpTemplateTrackerSSD.cpp 4666 2014-02-16 16:21:33Z 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 
43 #include <visp/vpTemplateTrackerSSD.h>
44 
46  : vpTemplateTracker(warp), DI(), temp()
47 {
48  dW.resize(2,nbParam);
49  G.resize(nbParam);
52 
54 
55  X1.resize(2);
56  X2.resize(2);
57  DI.resize(2);
58 }
59 
61 {
62  double erreur=0;
63  double IW,Tij;
64  int i,j;
65  double i2,j2;
66  int Nbpoint=0;
67 
68  Warp->computeCoeff(tp);
69  for(unsigned int point=0;point<templateSize;point++)
70  {
71  i=ptTemplate[point].y;
72  j=ptTemplate[point].x;
73  X1[0]=j;X1[1]=i;
74  Warp->computeDenom(X1,tp);
75  Warp->warpX(X1,X2,tp);
76 
77  j2=X2[0];i2=X2[1];
78  if((i2>=0)&&(j2>=0)&&(i2<I.getHeight()-1)&&(j2<I.getWidth()-1))
79  {
80  Tij=ptTemplate[point].val;
81  if(!blur)
82  IW=I.getValue(i2,j2);
83  else
84  IW=BI.getValue(i2,j2);
85  //IW=getSubPixBspline4(I,i2,j2);
86  erreur+=((double)Tij-IW)*((double)Tij-IW);
87  Nbpoint++;
88  }
89  }
90  ratioPixelIn=(double)Nbpoint/(double)templateSize;
91 
92  if(Nbpoint==0)return 10e10;
93  return erreur/Nbpoint;
94 }
95 
96 
98 {
99  double erreur=0;
100  double IW,Tij;
101  int i,j;
102  double i2,j2;
103  int Nbpoint=0;
104 
105  if(pyrInitialised)
106  {
109  }
110 
111  Warp->computeCoeff(tp);
112  for(unsigned int point=0;point<templateSize;point++)
113  {
114  i=ptTemplate[point].y;
115  j=ptTemplate[point].x;
116  X1[0]=j;X1[1]=i;
117  Warp->computeDenom(X1,tp);
118  Warp->warpX(X1,X2,tp);
119 
120  j2=X2[0];i2=X2[1];
121  if((j2<I.getWidth()-1)&&(i2<I.getHeight()-1)&&(i2>0)&&(j2>0))
122  {
123  Tij=ptTemplate[point].val;
124  IW=I.getValue(i2,j2);
125  //IW=getSubPixBspline4(I,i2,j2);
126  erreur+=((double)Tij-IW)*((double)Tij-IW);
127  Nbpoint++;
128  }
129  }
130  if(Nbpoint==0)return 10e10;
131  return erreur/Nbpoint;
132 }
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:183
unsigned int getWidth() const
Definition: vpImage.h:159
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:1029
vpImage< double > BI
unsigned int templateSize
double getSSD(vpImage< unsigned char > &I, vpColVector &tp)
double getCost(const vpImage< unsigned char > &I, vpColVector &tp)
vpTemplateTrackerSSD(vpTemplateTrackerWarp *warp)
unsigned int * templateSizePyr
void resize(unsigned int i)
Set the size of the Row vector.
Definition: vpRowVector.h:91
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
unsigned int getHeight() const
Definition: vpImage.h:150
vpTemplateTrackerWarp * Warp
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94