ViSP  2.9.0
vpTemplateTrackerBSpline.cpp
1 /****************************************************************************
2  *
3  * $Id: vpTemplateTrackerBSpline.cpp 4574 2014-01-09 08:48:51Z 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/vpTemplateTrackerBSpline.h>
43 
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 
46 double vpTemplateTrackerBSpline::getSubPixBspline4(const vpImage<double> &I, double r, double t)
47 {
48  double res=0;
49  int cr=(int)(r);
50  int ct=(int)(t);
51  double er=(double)r-cr;
52  double et=(double)t-ct;
53  int height=(int)I.getHeight();//r
54  int width=(int)I.getWidth();//t
55  int tr,tt;
56  for(int ir=-1;ir<=2;ir++)
57  {
58  tr=ir+cr;
59  for(int it=-1;it<=2;it++)
60  {
61  tt=it+ct;
62  if(tr>=0 && tr <height && tt>=0 && tt <width)
63  res+=Bspline4((double)ir-er)*Bspline4((double)it-et)*I[tr][tt];
64  }
65  }
66  return res;
67 }
68 
69 double vpTemplateTrackerBSpline::Bspline4(double diff)
70 {
71  //double result;
72  double aDiff=vpMath::abs(diff);
73  if(aDiff<1.)
74  return (aDiff*aDiff*aDiff/2.-aDiff*aDiff+4./6.);
75  //return (0.5*(1.-aDiff)*(1.-aDiff)*(1.-aDiff)+0.5*(1.-aDiff)*(1.-aDiff)-0.5*(1.-aDiff)+1./6.);
76  else if(aDiff<2.)
77  return ((2.-aDiff)*(2.-aDiff)*(2.-aDiff)/6.);
78  else
79  return 0;
80 }
81 
82 #endif
unsigned int getWidth() const
Definition: vpImage.h:159
static Type abs(const Type &x)
Definition: vpMath.h:158
unsigned int getHeight() const
Definition: vpImage.h:150