ViSP  2.7.0
vpMbKltTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbKltTracker.h 4119 2013-02-08 10:30:53Z fspindle $
4  *
5  * Copyright (C) 2005 - 2013 Inria. All rights reserved.
6  *
7  * This software was developed at:
8  * IRISA/INRIA Rennes
9  * Projet Lagadic
10  * Campus Universitaire de Beaulieu
11  * 35042 Rennes Cedex
12  * http://www.irisa.fr/lagadic
13  *
14  * This file is part of the ViSP toolkit
15  *
16  * This file may be distributed under the terms of the Q Public License
17  * as defined by Trolltech AS of Norway and appearing in the file
18  * LICENSE included in the packaging of this file.
19  *
20  * Licensees holding valid ViSP Professional Edition licenses may
21  * use this file in accordance with the ViSP Commercial License
22  * Agreement provided with the Software.
23  *
24  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26  *
27  * Contact visp@irisa.fr if any conditions of this licensing are
28  * not clear to you.
29  *
30  * Description:
31  * Model based tracker using only KLT
32  *
33  * Authors:
34  * Romain Tallonneau
35  * Aurelien Yol
36  *
37  *****************************************************************************/
43 #ifndef vpMbKltTracker_h
44 #define vpMbKltTracker_h
45 
46 #include <visp/vpConfig.h>
47 
48 #ifdef VISP_HAVE_OPENCV
49 
50 #include <visp/vpMbTracker.h>
51 #include <visp/vpKltOpencv.h>
52 #include <visp/vpMbtKltPolygon.h>
53 #include <visp/vpMeterPixelConversion.h>
54 #include <visp/vpPixelMeterConversion.h>
55 #include <visp/vpDisplayX.h>
56 #include <visp/vpMbtKltXmlParser.h>
57 #include <visp/vpHomography.h>
58 #include <visp/vpRobust.h>
59 #include <visp/vpSubColVector.h>
60 #include <visp/vpSubMatrix.h>
61 #include <visp/vpExponentialMap.h>
62 #include <visp/vpMbtKltPolygon.h>
63 
212 class VISP_EXPORT vpMbKltTracker: virtual public vpMbTracker
213 {
214 protected:
216  IplImage* cur;
220  double angleAppears;
228  unsigned int maskBorder;
230  double lambda;
232  unsigned int maxIter;
236  double percentGood;
238  bool useOgre;
247 
248 public:
249 
250  vpMbKltTracker();
251  virtual ~vpMbKltTracker();
252 
253  virtual void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo,
254  const vpCameraParameters &cam, const vpColor& col, const unsigned int thickness=1,
255  const bool displayFullModel = false);
256  virtual void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
257  const vpColor& col, const unsigned int thickness=1, const bool displayFullModel = false);
258 
259 protected:
260  virtual void init(const vpImage<unsigned char>& I);
261  virtual void reinit(const vpImage<unsigned char>& I);
262 
263 public:
264  virtual void loadConfigFile(const std::string& configFile);
265  void loadConfigFile(const char* configFile);
266 
268  virtual inline double getAngleAppear() { return angleAppears; }
269 
271  virtual inline double getAngleDisappear() { return angleDisappears; }
272 
275 
281  inline CvPoint2D32f* getKltPoints() {return tracker.getFeatures();}
282 
283  std::vector<vpImagePoint> getKltImagePoints();
284 
285  std::map<int, vpImagePoint> getKltImagePointsWithId();
286 
292  inline vpKltOpencv getKltOpencv() { return tracker; }
293 
299  inline double getLambda() {return lambda;}
300 
306  inline unsigned int getMaskBorder() { return maskBorder; }
307 
313  inline unsigned int getMaxIter() {return maxIter;}
314 
320  inline int getNbKltPoints() {return tracker.getNbFeatures();}
321 
327  inline double getThresholdAcceptation() { return threshold_outlier;}
328 
329  void resetTracker();
330 
340  virtual inline void setAngleAppear(const double &a) { angleAppears = a; }
341 
351  virtual inline void setAngleDisappear(const double &a) { angleDisappears = a; }
352 
353  void setCameraParameters(const vpCameraParameters& cam);
354 
355  void setKltOpencv(const vpKltOpencv& t);
356 
362  inline void setLambda(const double lambda) {this->lambda = lambda;}
363 
369  void setMaskBorder(const unsigned int &e){ maskBorder = e; }
370 
376  inline void setMaxIter(const unsigned int max) {maxIter = max;}
377 
378  virtual void setOgreVisibilityTest(const bool &v);
379 
380  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo);
381 
387  inline void setThresholdAcceptation(const double th) {threshold_outlier = th;}
388 
389  virtual void testTracking();
390  virtual void track(const vpImage<unsigned char>& I);
391 
392 protected:
393  void computeVVS(const unsigned int &nbInfos, vpColVector &w);
394 
395  virtual void initFaceFromCorners(const std::vector<vpPoint>& corners, const unsigned int indexFace = -1);
396  virtual void initCylinder(const vpPoint& , const vpPoint , const double , const unsigned int ){};
397 
398  void preTracking(const vpImage<unsigned char>& I, unsigned int &nbInfos, unsigned int &nbFaceUsed);
399  bool postTracking(const vpImage<unsigned char>& I, vpColVector &w);
400 };
401 
402 #endif
403 #endif // VISP_HAVE_OPENCV
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimisation. Otherwise, compute it only on the first iteration.
CvPoint2D32f * getKltPoints()
void setThresholdAcceptation(const double th)
void setMaxIter(const unsigned int max)
virtual void track(const vpImage< unsigned char > &I)=0
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
CvPoint2D32f * getFeatures() const
Get the list of features.
Definition: vpKltOpencv.h:285
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
virtual void initFaceFromCorners(const std::vector< vpPoint > &corners, const unsigned int indexFace=-1)=0
IplImage * cur
Temporary OpenCV image for fast conversion.
Class to define colors available for display functionnalities.
Definition: vpColor.h:123
virtual void initCylinder(const vpPoint &, const vpPoint, const double, const unsigned int)
double percentGood
Percentage of good points, according to the initial number, that must have the tracker.
double getLambda()
double getThresholdAcceptation()
bool firstInitialisation
Flag to specify whether the init method is called the first or not (specific calls to realise in this...
virtual void resetTracker()=0
void setLambda(const double lambda)
Class that defines what is a point.
Definition: vpPoint.h:65
vpHomogeneousMatrix ctTc0
The estimated displacement of the pose between the current instant and the initial position...
virtual void init(const vpImage< unsigned char > &I)=0
virtual void setAngleAppear(const double &a)
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, const unsigned int thickness=1, const bool displayFullModel=false)=0
virtual void setCameraParameters(const vpCameraParameters &cam)
Definition: vpMbTracker.h:235
unsigned int getMaxIter()
unsigned int getMaskBorder()
unsigned int maskBorder
Erosion of the mask.
Generic class defining intrinsic camera parameters.
Main methods for a model-based tracker.
Definition: vpMbTracker.h:102
vpMbHiddenFaces< vpMbtKltPolygon > faces
Set of faces describing the object.
bool useOgre
Use Ogre3d for visibility tests.
vpKltOpencv getKltOpencv()
Model based tracker using only KLT.
bool firstTrack
First track() called.
virtual void loadConfigFile(const std::string &configFile)=0
vpKltOpencv tracker
Points tracker.
virtual double getAngleAppear()
double threshold_outlier
Threshold below which the weight associated to a point to consider this one as an outlier...
virtual void setAngleDisappear(const double &a)
double lambda
The gain of the virtual visual servoing stage.
void setMaskBorder(const unsigned int &e)
virtual double getAngleDisappear()
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 void testTracking()=0
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented with OpenCV.
Definition: vpKltOpencv.h:141
int getNbFeatures() const
Get the current number of features.
Definition: vpKltOpencv.h:297
double angleAppears
Angle used to detect a face apparition.
vpMbHiddenFaces< vpMbtKltPolygon > & getFaces()
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
double angleDisappears
Angle used to detect a face disparition.
vpHomogeneousMatrix c0Mo
Initial pose.