ViSP  2.10.0
vpMbKltTracker.h
1 /****************************************************************************
2  *
3  * $Id: vpMbKltTracker.h 5126 2015-01-05 22:07: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 #if (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
52 
53 #include <visp/vpMbTracker.h>
54 #include <visp/vpKltOpencv.h>
55 #include <visp/vpMeterPixelConversion.h>
56 #include <visp/vpPixelMeterConversion.h>
57 #include <visp/vpDisplayX.h>
58 #include <visp/vpMbtKltXmlParser.h>
59 #include <visp/vpHomography.h>
60 #include <visp/vpRobust.h>
61 #include <visp/vpSubColVector.h>
62 #include <visp/vpSubMatrix.h>
63 #include <visp/vpExponentialMap.h>
64 //#include <visp/vpMbtKltPolygon.h>
65 #include <visp/vpMbtDistanceKltPoints.h>
66 #include <visp/vpMbtDistanceCircle.h>
67 #include <visp/vpMbtDistanceCylinder.h>
68 
229 class VISP_EXPORT vpMbKltTracker: virtual public vpMbTracker
230 {
231 protected:
233 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
234  cv::Mat cur;
235 #else
236  IplImage *cur;
237 #endif
238  vpHomogeneousMatrix c0Mo;
245  unsigned int maskBorder;
247  double lambda;
249  unsigned int maxIter;
253  double percentGood;
261  std::list<vpMbtDistanceKltPoints*> kltPolygons;
263  std::list<vpMbtDistanceCylinder*> cylinders_disp;
265  std::list<vpMbtDistanceCircle*> circles_disp;
266 
267 public:
268  vpMbKltTracker();
269  virtual ~vpMbKltTracker();
270 
271  void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name="");
272  void addCylinder(const vpPoint &P1, const vpPoint &P2, const double r, const std::string &name="");
273  virtual void display(const vpImage<unsigned char>& I, const vpHomogeneousMatrix &cMo,
274  const vpCameraParameters &cam, const vpColor& col, const unsigned int thickness=1,
275  const bool displayFullModel = false);
276  virtual void display(const vpImage<vpRGBa>& I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
277  const vpColor& col, const unsigned int thickness=1, const bool displayFullModel = false);
278 
279 protected:
280  virtual void init(const vpImage<unsigned char>& I);
281  virtual void reinit(const vpImage<unsigned char>& I);
282 
283 public:
285  std::list<vpMbtDistanceCircle*> &getFeaturesCircle() { return circles_disp; }
287  std::list<vpMbtDistanceCylinder*> &getFeaturesCylinder() { return cylinders_disp; }
289  std::list<vpMbtDistanceKltPoints*> &getFeaturesKlt() { return kltPolygons; }
290  virtual void loadConfigFile(const std::string& configFile);
291  void loadConfigFile(const char* configFile);
292 
298 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
299  inline std::vector<cv::Point2f> getKltPoints() {return tracker.getFeatures();}
300 #else
301  inline CvPoint2D32f* getKltPoints() {return tracker.getFeatures();}
302 #endif
303 
304  std::vector<vpImagePoint> getKltImagePoints() const;
305 
306  std::map<int, vpImagePoint> getKltImagePointsWithId() const;
307 
313  inline vpKltOpencv getKltOpencv() const { return tracker; }
314 
320  virtual inline double getLambda() const {return lambda;}
321 
327  inline unsigned int getMaskBorder() const { return maskBorder; }
328 
334  virtual inline unsigned int getMaxIter() const {return maxIter;}
335 
341  inline int getNbKltPoints() const {return tracker.getNbFeatures();}
342 
348  inline double getThresholdAcceptation() const { return threshold_outlier;}
349 
350  void reInitModel(const vpImage<unsigned char>& I, const std::string &cad_name, const vpHomogeneousMatrix& cMo_,
351  const bool verbose=false);
352  void reInitModel(const vpImage<unsigned char>& I, const char* cad_name, const vpHomogeneousMatrix& cMo,
353  const bool verbose=false);
354  void resetTracker();
355 
356  void setCameraParameters(const vpCameraParameters& cam);
357 
358  void setKltOpencv(const vpKltOpencv& t);
359 
365  virtual inline void setLambda(const double gain) {this->lambda = gain;}
366 
372  inline void setMaskBorder(const unsigned int &e){ maskBorder = e; }
373 
379  virtual inline void setMaxIter(const unsigned int max) {maxIter = max;}
380 
388  virtual void setOgreVisibilityTest(const bool &v){
390 #ifdef VISP_HAVE_OGRE
391  faces.getOgreContext()->setWindowName("MBT Klt");
392 #endif
393  }
394 
395  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix& cdMo);
396 
402  inline void setThresholdAcceptation(const double th) {threshold_outlier = th;}
403 
404  virtual void testTracking();
405  virtual void track(const vpImage<unsigned char>& I);
406 
407 protected:
408  void computeVVS(const unsigned int &nbInfos, vpColVector &w);
409 
410  virtual void initFaceFromCorners(vpMbtPolygon &polygon);
411  virtual void initFaceFromLines(vpMbtPolygon &polygon);
412  virtual void initCircle(const vpPoint&, const vpPoint &, const vpPoint &, const double, const int,
413  const std::string &name="");
414  virtual void initCylinder(const vpPoint&, const vpPoint &, const double, const int,
415  const std::string &name="");
416 
417  void preTracking(const vpImage<unsigned char>& I, unsigned int &nbInfos, unsigned int &nbFaceUsed);
418  bool postTracking(const vpImage<unsigned char>& I, vpColVector &w);
419 };
420 
421 #endif
422 #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.
std::list< vpMbtDistanceKltPoints * > kltPolygons
Vector of the cylinders used here only to display the full model.
void setThresholdAcceptation(const double th)
virtual void track(const vpImage< unsigned char > &I)=0
virtual void setLambda(const double gain)
unsigned int maxIter
The maximum iteration of the virtual visual servoing stage.
std::vector< cv::Point2f > getFeatures() const
Get the list of current features.
Definition: vpKltOpencv.h:107
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
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 initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, const double radius, const int idFace=0, const std::string &name="")=0
std::list< vpMbtDistanceCylinder * > & getFeaturesCylinder()
virtual double getLambda() const
std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
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
Class that defines what is a point.
Definition: vpPoint.h:65
std::vector< cv::Point2f > getKltPoints()
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
unsigned int getMaskBorder() const
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
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:67
virtual void setCameraParameters(const vpCameraParameters &camera)
Definition: vpMbTracker.h:407
unsigned int maskBorder
Erosion of the mask.
virtual void initFaceFromCorners(vpMbtPolygon &polygon)=0
Generic class defining intrinsic camera parameters.
std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
Main methods for a model-based tracker.
Definition: vpMbTracker.h:106
Model based tracker using only KLT.
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)
cv::Mat cur
Temporary OpenCV image for fast conversion.
double lambda
The gain of the virtual visual servoing stage.
int getNbKltPoints() const
vpKltOpencv getKltOpencv() const
std::list< vpMbtDistanceCircle * > circles_disp
Vector of the circles used here only to display the full model.
virtual void setOgreVisibilityTest(const bool &v)
void setMaskBorder(const unsigned int &e)
std::list< vpMbtDistanceCylinder * > cylinders_disp
Vector of the cylinders used here only to display the full model.
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 initFaceFromLines(vpMbtPolygon &polygon)=0
virtual void setOgreVisibilityTest(const bool &v)
virtual void testTracking()=0
Wrapper for the KLT (Kanade-Lucas-Tomasi) feature tracker implemented in OpenCV.
Definition: vpKltOpencv.h:79
int getNbFeatures() const
Get the number of current features.
Definition: vpKltOpencv.h:121
double getThresholdAcceptation() const
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
virtual unsigned int getMaxIter() const
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const int idFace=0, const std::string &name="")=0