Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpTemplateTrackerSSD.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 
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;
61  int Nbpoint=0;
62 
63  Warp->computeCoeff(tp);
64  for(unsigned int point=0;point<templateSize;point++)
65  {
66  int i=ptTemplate[point].y;
67  int j=ptTemplate[point].x;
68  X1[0]=j;X1[1]=i;
69  Warp->computeDenom(X1,tp);
70  Warp->warpX(X1,X2,tp);
71 
72  double j2=X2[0];
73  double i2=X2[1];
74  if((i2>=0)&&(j2>=0)&&(i2<I.getHeight()-1)&&(j2<I.getWidth()-1))
75  {
76  double Tij=ptTemplate[point].val;
77  if(!blur)
78  IW=I.getValue(i2,j2);
79  else
80  IW=BI.getValue(i2,j2);
81  //IW=getSubPixBspline4(I,i2,j2);
82  erreur+=((double)Tij-IW)*((double)Tij-IW);
83  Nbpoint++;
84  }
85  }
86  ratioPixelIn=(double)Nbpoint/(double)templateSize;
87 
88  if(Nbpoint==0)return 10e10;
89  return erreur/Nbpoint;
90 }
91 
92 
94 {
95  double erreur=0;
96  double IW;
97  unsigned int Nbpoint=0;
98 
99  if(pyrInitialised)
100  {
103  }
104 
105  Warp->computeCoeff(tp);
106  for(unsigned int point=0;point<templateSize;point++)
107  {
108  int i=ptTemplate[point].y;
109  int j=ptTemplate[point].x;
110  X1[0]=j;X1[1]=i;
111  Warp->computeDenom(X1,tp);
112  Warp->warpX(X1,X2,tp);
113 
114  double j2=X2[0];
115  double i2=X2[1];
116  if((j2<I.getWidth()-1)&&(i2<I.getHeight()-1)&&(i2>0)&&(j2>0))
117  {
118  double Tij=ptTemplate[point].val;
119  IW=I.getValue(i2,j2);
120  //IW=getSubPixBspline4(I,i2,j2);
121  erreur+=((double)Tij-IW)*((double)Tij-IW);
122  Nbpoint++;
123  }
124  }
125  if(Nbpoint==0)return 10e10;
126  return erreur/Nbpoint;
127 }
unsigned int getWidth() const
Definition: vpImage.h:226
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:1477
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:205
unsigned int * templateSizePyr
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
unsigned int getHeight() const
Definition: vpImage.h:175
vpTemplateTrackerWarp * Warp
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:225