ViSP  2.9.0
vpMbKltTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbKltTracker.h 4649 2014-02-07 14:57:11Z 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  * Model based tracker using only KLT
35  *
36  * Authors:
37  * Romain Tallonneau
38  * Aurelien Yol
39  *
40  *****************************************************************************/
46 #ifndef vpMbKltTracker_h
47 #define vpMbKltTracker_h
48 
49 #include <visp/vpConfig.h>
50 
51 #ifdef VISP_HAVE_OPENCV
52 
53 #include <visp/vpMbTracker.h>
54 #include <visp/vpKltOpencv.h>
55 #include <visp/vpMbtKltPolygon.h>
56 #include <visp/vpMeterPixelConversion.h>
57 #include <visp/vpPixelMeterConversion.h>
58 #include <visp/vpDisplayX.h>
59 #include <visp/vpMbtKltXmlParser.h>
60 #include <visp/vpHomography.h>
61 #include <visp/vpRobust.h>
62 #include <visp/vpSubColVector.h>
63 #include <visp/vpSubMatrix.h>
64 #include <visp/vpExponentialMap.h>
65 #include <visp/vpMbtKltPolygon.h>
66 
227 class VISP_EXPORT vpMbKltTracker: virtual public vpMbTracker
228 {
229 protected:
231  IplImage* cur;
235  double angleAppears;
243  unsigned int maskBorder;
245  double lambda;
247  unsigned int maxIter;
251  double percentGood;
253  bool useOgre;
263  double distNearClip;
265  double distFarClip;
267  unsigned int clippingFlag;
268 
269 public:
270 
271  vpMbKltTracker();
272  virtual ~vpMbKltTracker();
273 
274  virtual void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo,
275  const vpCameraParameters &cam, const vpColor& col, const unsigned int thickness=1,
276  const bool displayFullModel = false);
277  virtual void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
278  const vpColor& col, const unsigned int thickness=1, const bool displayFullModel = false);
279 
280 protected:
281  virtual void init(const vpImage<unsigned char>& I);
282  virtual void reinit(const vpImage<unsigned char>& I);
283 
284 public:
285  virtual void loadConfigFile(const std::string& configFile);
286  void loadConfigFile(const char* configFile);
287 
289  virtual inline double getAngleAppear() const { return angleAppears; }
290 
292  virtual inline double getAngleDisappear() const { return angleDisappears; }
293 
301  virtual inline unsigned int getClipping() const { return clippingFlag; }
302 
304  inline vpMbHiddenFaces<vpMbtKltPolygon>& getFaces() { return faces;}
305 
311  virtual inline double getFarClippingDistance() const { return distFarClip; }
312 
318  inline CvPoint2D32f* getKltPoints() {return tracker.getFeatures();}
319 
320  std::vector<vpImagePoint> getKltImagePoints() const;
321 
322  std::map<int, vpImagePoint> getKltImagePointsWithId() const;
323 
329  inline vpKltOpencv getKltOpencv() const { return tracker; }
330 
336  virtual inline double getLambda() const {return lambda;}
337 
343  inline unsigned int getMaskBorder() const { return maskBorder; }
344 
350  virtual inline unsigned int getMaxIter() const {return maxIter;}
351 
357  inline int getNbKltPoints() const {return tracker.getNbFeatures();}
358 
364  virtual inline double getNearClippingDistance() const { return distNearClip; }
365 
371  inline double getThresholdAcceptation() const { return threshold_outlier;}
372 
373  void resetTracker();
374 
384  virtual inline void setAngleAppear(const double &a) { angleAppears = a; }
385 
395  virtual inline void setAngleDisappear(const double &a) { angleDisappears = a; }
396 
397  void setCameraParameters(const vpCameraParameters& cam);
398 
399  virtual void setClipping(const unsigned int &flags);
400 
401  virtual void setFarClippingDistance(const double &dist);
402 
403  void setKltOpencv(const vpKltOpencv& t);
404 
410  virtual inline void setLambda(const double gain) {this->lambda = gain;}
411 
417  inline void setMaskBorder(const unsigned int &e){ maskBorder = e; }
418 
424  virtual inline void setMaxIter(const unsigned int max) {maxIter = max;}
425 
426  virtual void setNearClippingDistance(const double &dist);
427 
428  virtual void setOgreVisibilityTest(const bool &v);
429 
430  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo);
431 
437  inline void setThresholdAcceptation(const double th) {threshold_outlier = th;}
438 
439  virtual void testTracking();
440  virtual void track(const vpImage<unsigned char>& I);
441 
442 protected:
443  void computeVVS(const unsigned int &nbInfos, vpColVector &w);
444 
445  virtual void initFaceFromCorners(const std::vector<vpPoint>& corners, const unsigned int indexFace = -1);
446  virtual void initCylinder(const vpPoint&, const vpPoint &, const double, const unsigned int ){};
447 
448  void preTracking(const vpImage<unsigned char>& I, unsigned int &nbInfos, unsigned int &nbFaceUsed);
449  bool postTracking(const vpImage<unsigned char>& I, vpColVector &w);
450 };
451 
452 #endif
453 #endif // VISP_HAVE_OPENCV
bool compute_interaction
If true, compute the interaction matrix at each iteration of the minimization. Otherwise, compute it only on the first iteration.
CvPoint2D32f * getKltPoints()
void setThresholdAcceptation(const double th)
double distFarClip
Distance for near clipping.
virtual void track(const vpImage< unsigned char > &I)=0
double distNearClip
Distance for near clipping.
unsigned int clippingFlag
Flags specifying which clipping to used.
virtual void setLambda(const double gain)
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
CvPoint2D32f * getFeatures() const
Get the list of features.
Definition: vpKltOpencv.h:175
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:125
double percentGood
Percentage of good points, according to the initial number, that must have the tracker.
virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const unsigned int)
virtual double getLambda() const
bool firstInitialisation
Flag to specify whether the init method is called the first or not (specific calls to realize in this...
virtual void resetTracker()=0
virtual double getFarClippingDistance() const
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 double getAngleAppear() const
unsigned int getMaskBorder() const
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 &camera)
Definition: vpMbTracker.h:233
virtual double getNearClippingDistance() const
virtual unsigned int getClipping() const
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.
Model based tracker using only KLT.
virtual double getAngleDisappear() const
bool firstTrack
First track() called.
virtual void loadConfigFile(const std::string &configFile)=0
vpKltOpencv tracker
Points tracker.
double threshold_outlier
Threshold below which the weight associated to a point to consider this one as an outlier...
virtual void setMaxIter(const unsigned int max)
virtual void setAngleDisappear(const double &a)
double lambda
The gain of the virtual visual servoing stage.
int getNbKltPoints() const
vpKltOpencv getKltOpencv() const
void setMaskBorder(const unsigned int &e)
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 in OpenCV.
Definition: vpKltOpencv.h:103
int getNbFeatures() const
Get the current number of features.
Definition: vpKltOpencv.h:187
double getThresholdAcceptation() const
double angleAppears
Angle used to detect a face appearance.
vpMbHiddenFaces< vpMbtKltPolygon > & getFaces()
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
virtual unsigned int getMaxIter() const
double angleDisappears
Angle used to detect a face disappearance.
vpHomogeneousMatrix c0Mo
Initial pose.