Visual Servoing Platform  version 3.2.1 under development (2019-08-08)
vpMbKltTracker.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Model based tracker using only KLT
33  *
34  * Authors:
35  * Romain Tallonneau
36  * Aurelien Yol
37  *
38  *****************************************************************************/
44 #ifndef vpMbKltTracker_h
45 #define vpMbKltTracker_h
46 
47 #include <visp3/core/vpConfig.h>
48 
49 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
50 
51 #include <visp3/core/vpExponentialMap.h>
52 #include <visp3/core/vpMeterPixelConversion.h>
53 #include <visp3/core/vpPixelMeterConversion.h>
54 #include <visp3/core/vpSubColVector.h>
55 #include <visp3/core/vpSubMatrix.h>
56 #include <visp3/klt/vpKltOpencv.h>
57 #include <visp3/mbt/vpMbTracker.h>
58 #include <visp3/mbt/vpMbtDistanceCircle.h>
59 #include <visp3/mbt/vpMbtDistanceKltCylinder.h>
60 #include <visp3/mbt/vpMbtDistanceKltPoints.h>
61 #include <visp3/vision/vpHomography.h>
62 
216 class VISP_EXPORT vpMbKltTracker : public virtual vpMbTracker
217 {
218  friend class vpMbKltMultiTracker;
220 
221 protected:
223 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
224  cv::Mat cur;
225 #else
226  IplImage *cur;
227 #endif
234  unsigned int maskBorder;
240  double percentGood;
247  std::list<vpMbtDistanceKltPoints *> kltPolygons;
249  std::list<vpMbtDistanceKltCylinder *> kltCylinders;
251  std::list<vpMbtDistanceCircle *> circles_disp;
253  unsigned int m_nbInfos;
255  unsigned int m_nbFaceUsed;
267  std::vector<std::vector<double> > m_featuresToBeDisplayedKlt;
268 
269 public:
270  vpMbKltTracker();
271  virtual ~vpMbKltTracker();
272 
275 
276  void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name = "");
277  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
278  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
279  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
280  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
281 
283  virtual std::list<vpMbtDistanceCircle *> &getFeaturesCircle() { return circles_disp; }
285  virtual std::list<vpMbtDistanceKltCylinder *> &getFeaturesKltCylinder() { return kltCylinders; }
287  virtual std::list<vpMbtDistanceKltPoints *> &getFeaturesKlt() { return kltPolygons; }
288 
294 #if (VISP_HAVE_OPENCV_VERSION >= 0x020408)
295  inline std::vector<cv::Point2f> getKltPoints() const { return tracker.getFeatures(); }
296 #else
297  inline CvPoint2D32f *getKltPoints() { return tracker.getFeatures(); }
298 #endif
299 
300  std::vector<vpImagePoint> getKltImagePoints() const;
301 
302  std::map<int, vpImagePoint> getKltImagePointsWithId() const;
303 
309  inline vpKltOpencv getKltOpencv() const { return tracker; }
310 
316  inline unsigned int getKltMaskBorder() const { return maskBorder; }
317 
323  inline int getKltNbPoints() const { return tracker.getNbFeatures(); }
324 
331  inline double getKltThresholdAcceptation() const { return threshold_outlier; }
332 
333  virtual inline vpColVector getError() const { return m_error_klt; }
334 
335  virtual inline vpColVector getRobustWeights() const { return m_w_klt; }
336 
337  virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int width, unsigned int height,
338  const vpHomogeneousMatrix &cMo,
339  const vpCameraParameters &cam,
340  const bool displayFullModel=false);
341 
342  virtual void loadConfigFile(const std::string &configFile);
343 
344  virtual void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name,
345  const vpHomogeneousMatrix &cMo_, const bool verbose = false,
347  void resetTracker();
348 
349  void setCameraParameters(const vpCameraParameters &cam);
350 
356  inline void setKltMaskBorder(const unsigned int &e)
357  {
358  maskBorder = e;
359  // if(useScanLine)
360  faces.getMbScanLineRenderer().setMaskBorder(maskBorder);
361  }
362 
363  virtual void setKltOpencv(const vpKltOpencv &t);
364 
370  inline void setKltThresholdAcceptation(const double th) { threshold_outlier = th; }
371 
380  virtual void setOgreVisibilityTest(const bool &v)
381  {
383 #ifdef VISP_HAVE_OGRE
384  faces.getOgreContext()->setWindowName("MBT Klt");
385 #endif
386  }
387 
393  virtual void setScanLineVisibilityTest(const bool &v)
394  {
396 
397  for (std::list<vpMbtDistanceKltPoints *>::const_iterator it = kltPolygons.begin(); it != kltPolygons.end(); ++it)
398  (*it)->useScanLine = v;
399  }
400 
401  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cdMo);
402  virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cdMo);
403 
410  virtual void setProjectionErrorComputation(const bool &flag)
411  {
412  if (flag)
413  std::cerr << "This option is not yet implemented in vpMbKltTracker, "
414  "projection error computation set to false."
415  << std::endl;
416  }
417 
418  void setUseKltTracking(const std::string &name, const bool &useKltTracking);
419 
420  virtual void testTracking();
421  virtual void track(const vpImage<unsigned char> &I);
422  virtual void track(const vpImage<vpRGBa> &I_color);
423 
428 
435  /* vp_deprecated */ inline unsigned int getMaskBorder() const { return maskBorder; }
442  /* vp_deprecated */ inline int getNbKltPoints() const { return tracker.getNbFeatures(); }
443 
451  /* vp_deprecated */ inline double getThresholdAcceptation() const { return threshold_outlier; }
457  /* vp_deprecated */ inline void setMaskBorder(const unsigned int &e)
458  {
459  maskBorder = e;
460  // if(useScanLine)
461  faces.getMbScanLineRenderer().setMaskBorder(maskBorder);
462  }
463 
470  /* vp_deprecated */ inline void setThresholdAcceptation(const double th) { threshold_outlier = th; }
471 
473 
474 protected:
477  void computeVVS();
478  virtual void computeVVSInit();
480 
481  virtual std::vector<std::vector<double> > getFeaturesForDisplayKlt();
482 
483  virtual void init(const vpImage<unsigned char> &I);
484  virtual void initFaceFromCorners(vpMbtPolygon &polygon);
485  virtual void initFaceFromLines(vpMbtPolygon &polygon);
486  virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, const double, const int,
487  const std::string &name = "");
488  virtual void initCylinder(const vpPoint &, const vpPoint &, const double, const int, const std::string &name = "");
489 
490  void preTracking(const vpImage<unsigned char> &I);
492  virtual void reinit(const vpImage<unsigned char> &I);
493  virtual void setPose(const vpImage<unsigned char> * const I, const vpImage<vpRGBa> * const I_color,
494  const vpHomogeneousMatrix &cdMo);
496 };
497 
498 #endif
499 #endif // VISP_HAVE_OPENCV
void setWindowName(const Ogre::String &n)
Definition: vpAROgre.h:269
void setThresholdAcceptation(const double th)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
virtual ~vpMbKltTracker()
virtual void setScanLineVisibilityTest(const bool &v)
virtual void track(const vpImage< unsigned char > &I)=0
virtual void computeVVSInteractionMatrixAndResidu()=0
virtual void addCircle(const vpPoint &P1, const vpPoint &P2, const vpPoint &P3, const double r, const std::string &name="")
virtual void setUseKltTracking(const std::string &name, const bool &useKltTracking)
virtual void computeVVSInit()=0
vpMbHiddenFaces< vpMbtPolygon > faces
Set of faces describing the object.
Definition: vpMbTracker.h:143
std::vector< cv::Point2f > getFeatures() const
Get the list of current features.
Definition: vpKltOpencv.h:105
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual std::list< vpMbtDistanceKltPoints * > & getFeaturesKlt()
virtual void setProjectionErrorComputation(const bool &flag)
virtual void loadConfigFile(const std::string &configFile)
std::vector< std::vector< double > > m_featuresToBeDisplayedKlt
Display features.
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
std::list< vpMbtDistanceKltCylinder * > kltCylinders
vpHomogeneousMatrix cMo
The current pose.
Definition: vpMbTracker.h:113
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, const double radius, const int idFace=0, const std::string &name="")=0
vpMbScanLine & getMbScanLineRenderer()
vpColVector m_weightedError_klt
Weighted error.
Hybrid stereo (or more) tracker based on moving-edges and keypoints tracked using KLT tracker...
double getKltThresholdAcceptation() const
virtual vpColVector getError() const
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
void setKltMaskBorder(const unsigned int &e)
virtual void resetTracker()=0
Class that defines what is a point.
Definition: vpPoint.h:58
int getKltNbPoints() const
virtual void postTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages)
vpCameraParameters cam
The camera parameters.
Definition: vpMbTracker.h:111
unsigned int getKltMaskBorder() const
vpHomogeneousMatrix ctTc0
virtual void init(const vpImage< unsigned char > &I)=0
unsigned int getMaskBorder() const
std::vector< cv::Point2f > getKltPoints() const
virtual std::map< std::string, std::vector< vpImagePoint > > getKltImagePoints() const
vpAROgre * getOgreContext()
vpRobust m_robust_klt
Robust.
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
void setKltThresholdAcceptation(const double th)
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const bool displayFullModel=false)=0
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:66
virtual void setCameraParameters(const vpCameraParameters &camera)
Definition: vpMbTracker.h:483
virtual std::list< vpMbtDistanceCircle * > & getFeaturesCircle()
virtual std::map< std::string, std::vector< cv::Point2f > > getKltPoints() const
unsigned int maskBorder
Erosion of the mask.
virtual void initFaceFromCorners(vpMbtPolygon &polygon)=0
Generic class defining intrinsic camera parameters.
unsigned int m_nbFaceUsed
Main methods for a model-based tracker.
Definition: vpMbTracker.h:104
virtual void preTracking(std::map< std::string, const vpImage< unsigned char > * > &mapOfImages)
Model based tracker using only KLT.
vpKltOpencv tracker
Points tracker.
double threshold_outlier
virtual void setKltOpencv(const vpKltOpencv &t)
virtual std::map< std::string, std::map< int, vpImagePoint > > getKltImagePointsWithId() const
cv::Mat cur
Temporary OpenCV image for fast conversion.
int getNbKltPoints() const
virtual vpColVector getRobustWeights() const
vpColVector m_w_klt
Robust weights.
vpKltOpencv getKltOpencv() const
std::list< vpMbtDistanceCircle * > circles_disp
Vector of the circles used here only to display the full model.
virtual std::list< vpMbtDistanceKltCylinder * > & getFeaturesKltCylinder()
virtual void setOgreVisibilityTest(const bool &v)
void setMaskBorder(const unsigned int &e)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
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. Thus to enable this ...
Definition: vpKltOpencv.h:78
int getNbFeatures() const
Get the number of current features.
Definition: vpKltOpencv.h:120
Contains an M-Estimator and various influence function.
Definition: vpRobust.h:58
double getThresholdAcceptation() const
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
virtual void setScanLineVisibilityTest(const bool &v)
Definition: vpMbTracker.h:597
unsigned int m_nbInfos
vpColVector m_error_klt
(s - s*)
virtual std::vector< std::vector< double > > getFeaturesForDisplayKlt()
std::list< vpMbtDistanceKltPoints * > kltPolygons
Model based stereo (or more) tracker using only KLT.
vpHomogeneousMatrix c0Mo
Initial pose.
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const int idFace=0, const std::string &name="")=0
vpMatrix m_L_klt
Interaction matrix.