ViSP  2.6.2
vpMeTracker.cpp
1 /****************************************************************************
2 *
3 * $Id: vpMeTracker.cpp 3672 2012-04-04 15:49:57Z ayol $
4 *
5 * This file is part of the ViSP software.
6 * Copyright (C) 2005 - 2012 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 *
34 * Description:
35 * Moving edges.
36 *
37 * Authors:
38 * Andrew Comport
39 *
40 *****************************************************************************/
41 
49 #include <visp/vpMeTracker.h>
50 #include <visp/vpDisplay.h>
51 #include <visp/vpColor.h>
52 
53 #include <visp/vpTrackingException.h>
54 #include <visp/vpDebug.h>
55 #include <algorithm>
56 
57 #define DEBUG_LEVEL1 0
58 #define DEBUG_LEVEL2 0
59 
60 void
62 {
63  vpTracker::init() ;
64  p.resize(2) ;
66 }
67 
69 {
70  init();
71  me = NULL ;
72  nGoodElement = 0;
73  init_range = 1;
74 
75  #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
76  query_range = 0;
77  display_point = false ;
78  #endif
79 }
80 
81 vpMeTracker::vpMeTracker(const vpMeTracker& meTracker):vpTracker(meTracker)
82 {
83  init();
84 
85  me = meTracker.me;
86  list = meTracker.list;
87  nGoodElement = meTracker.nGoodElement;
88  init_range = meTracker.init_range;
89  selectDisplay = meTracker.selectDisplay;
90 
91  #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
92  display_point = meTracker.display_point;
93  query_range = meTracker.query_range;
94  #endif
95 }
96 
98 {
99  list.clear();
100 }
101 
104 {
105  list = p.list;
106  me = p.me;
108 
109  return *this;
110 }
111 
112 static bool isSuppressZero(const vpMeSite& P){
113  return (P.getState() == vpMeSite::NO_SUPPRESSION);
114 }
115 
116 unsigned int
118 {
119  unsigned int number_signal=0;
120 
121  // Loop through all the points tracked from the contour
122  number_signal = static_cast<unsigned int>(std::count_if(list.begin(), list.end(), isSuppressZero));
123  return number_signal;
124 }
125 
126 unsigned int
128 {
129  return list.size();
130 
131 }
132 
133 int
134 vpMeTracker::outOfImage(int i, int j, int half, int rows, int cols)
135 {
136  return (! ((i> half+2) &&
137  (i< rows -(half+2)) &&
138  (j>half+2) &&
139  (j<cols-(half+2)))
140  ) ;
141 }
142 
143 int
144 vpMeTracker::outOfImage(vpImagePoint iP, int half, int rows, int cols)
145 {
146  int i = vpMath::round(iP.get_i());
147  int j = vpMath::round(iP.get_j());
148  return (! ((i> half+2) &&
149  (i< rows -(half+2)) &&
150  (j>half+2) &&
151  (j<cols-(half+2)))
152  ) ;
153 }
154 
155 
160 void
162 {
163  // Must set range to 0
164  unsigned int range_tmp = me->getRange();
166 
167  nGoodElement=0;
168 
169  int d = 0;
170  vpImagePoint ip1, ip2;
171 
172  // Loop through list of sites to track
173  for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ++it){
174  vpMeSite refp = *it;//current reference pixel
175 
176  d++ ;
177  // If element hasn't been suppressed
178  if(refp.getState() == vpMeSite::NO_SUPPRESSION)
179  {
180  try {
181  refp.track(I,me,false);
182  }
183  catch(...)
184  {
185  // EM verifier quel signal est de sortie !!!
186  vpERROR_TRACE("Error caught") ;
187  throw ;
188  }
190  }
191 
192 
193 #if (DEBUG_LEVEL2)
194  {
195  double a,b ;
196  a = refp.i_1 - refp.i ;
197  b = refp.j_1 - refp.j ;
198  if(refp.getState() == vpMeSite::NO_SUPPRESSION) {
199  ip1.set_i( refp.i );
200  ip1.set_j( refp.j );
201  ip2.set_i( refp.i+a );
202  ip2.set_j( refp.j+b );
204  }
205  }
206 #endif
207  *it = refp;
208  }
209 
210  /*
211  if (res != OK)
212  {
213  std::cout<< "In vpMeTracker::initTracking(): " ;
214  switch (res)
215  {
216  case ERR_TRACKING:
217  std::cout << "vpMeTracker::initTracking:Track return ERR_TRACKING " << std::endl ;
218  break ;
219  case fatalError:
220  std::cout << "vpMeTracker::initTracking:Track return fatalError" << std::endl ;
221  break ;
222  default:
223  std::cout << "vpMeTracker::initTracking:Track return error " << res << std::endl ;
224  }
225  return res ;
226  }
227  */
228 
229  me->setRange(range_tmp);
230 }
231 
232 
233 void
235 {
236  if (list.empty())
237  {
238  vpDERROR_TRACE(2, "Tracking error: too few pixel to track");
240  "too few pixel to track")) ;
241 
242  }
243 
244  vpImagePoint ip1, ip2;
245  nGoodElement=0;
246  // int d =0;
247  // Loop through list of sites to track
248  for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ++it){
249  vpMeSite s = *it;//current reference pixel
250 
251  // d++ ;
252  // If element hasn't been suppressed
254  {
255 
256  try{
257  // vpERROR_TRACE("%d",d ) ;
258  // vpERROR_TRACE("range %d",me->range) ;
259  s.track(I,me,true);
260  }
261  catch(vpTrackingException)
262  {
263  vpERROR_TRACE("catch exception ") ;
265  }
266 
267  if(s.getState() != vpMeSite::THRESHOLD)
268  {
269  nGoodElement++;
270 
271 #if (DEBUG_LEVEL2)
272  {
273  double a,b ;
274  a = s.i_1 - s.i ;
275  b = s.j_1 - s.j ;
277  ip1.set_i( s.i );
278  ip1.set_j( s.j );
279  ip2.set_i( s.i+a*5 );
280  ip2.set_j( s.j+b*5 );
282  }
283  }
284 #endif
285 
286  }
287  *it = s;
288  }
289  }
290 }
291 
304 void
306 {
307 #if (DEBUG_LEVEL1)
308  {
309  std::cout <<"begin vpMeTracker::displayList() " << std::endl ;
310  std::cout<<" There are "<<list.size()<< " sites in the list " << std::endl ;
311  }
312 #endif
313  for(std::list<vpMeSite>::const_iterator it=list.begin(); it!=list.end(); ++it){
314  vpMeSite p = *it;
315  p.display(I);
316  }
317 }
318 
325 void
326 vpMeTracker::display(const vpImage<unsigned char>& I,vpColVector &w, unsigned int &index_w)
327 {
328  for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ++it){
329  vpMeSite P = *it;
330 
332  {
333  P.weight = w[index_w];
334  index_w++;
335  }
336 
337  *it = P;
338  }
339  display(I);
340 }
341 
342 #undef DEBUG_LEVEL1
343 #undef DEBUG_LEVEL2
344 
345 
void set_j(const double j)
Definition: vpImagePoint.h:156
unsigned int getRange() const
Definition: vpMe.h:236
virtual void displayArrow(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color=vpColor::white, unsigned int w=4, unsigned int h=2, unsigned int thickness=1)=0
double get_i() const
Definition: vpImagePoint.h:181
void display(const vpImage< unsigned char > &I)
Definition: vpMeSite.cpp:634
unsigned int numberOfSignal()
#define vpERROR_TRACE
Definition: vpDebug.h:379
unsigned int totalNumberOfSignal()
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'...
Definition: vpMeSite.h:76
int outOfImage(int i, int j, int half, int rows, int cols)
void set_i(const double i)
Definition: vpImagePoint.h:145
int i
Definition: vpMeSite.h:98
#define vpDERROR_TRACE
Definition: vpDebug.h:431
static const vpColor green
Definition: vpColor.h:168
static int round(const double x)
Definition: vpMath.h:228
double get_j() const
Definition: vpImagePoint.h:192
Class that defines what is a feature generic tracker.
Definition: vpTracker.h:69
vpMeSiteState getState() const
Definition: vpMeSite.h:202
std::list< vpMeSite > list
Definition: vpMeTracker.h:80
Error that can be emited by the vpTracker class and its derivates.
vpMeTracker & operator=(vpMeTracker &f)
void track(const vpImage< unsigned char > &I)
Track sampled pixels.
bool display_point
Definition: vpMeTracker.h:174
Contains abstract elements for a Distance to Feature type feature.
Definition: vpMeTracker.h:71
int nGoodElement
Definition: vpMeTracker.h:84
void setState(const vpMeSiteState &flag)
Definition: vpMeSite.h:189
int j_1
Definition: vpMeSite.h:99
int j
Definition: vpMeSite.h:98
double weight
Definition: vpMeSite.h:110
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
virtual ~vpMeTracker()
Definition: vpMeTracker.cpp:97
void track(const vpImage< unsigned char > &im, const vpMe *me, const bool test_contraste=true)
Definition: vpMeSite.cpp:370
vpMe * me
Moving edges initialisation parameters.
Definition: vpMeTracker.h:82
void initTracking(const vpImage< unsigned char > &I)
void init()
Default initialization.
Definition: vpTracker.cpp:54
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:92
void setRange(const unsigned int &r)
Definition: vpMe.h:229
int i_1
Definition: vpMeSite.h:99
vpMeSite::vpMeSiteDisplayType selectDisplay
Definition: vpMeTracker.h:87
virtual void display(const vpImage< unsigned char > &I, vpColor col)=0
unsigned int init_range
Definition: vpMeTracker.h:83
vpColVector p
Definition: vpTracker.h:78
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94