Visual Servoing Platform  version 3.2.1 under development (2019-08-21) under development (2019-08-21)
vpMbEdgeKltTracker.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  * Hybrid tracker based on edges (vpMbt) and points of interests (KLT)
33  *
34  * Authors:
35  * Romain Tallonneau
36  * Aurelien Yol
37  *
38  *****************************************************************************/
39 
45 #ifndef vpMbEdgeKltTracker_HH
46 #define vpMbEdgeKltTracker_HH
47 
48 #include <visp3/core/vpConfig.h>
49 
50 #if defined(VISP_HAVE_MODULE_KLT) && (defined(VISP_HAVE_OPENCV) && (VISP_HAVE_OPENCV_VERSION >= 0x020100))
51 
52 #include <visp3/core/vpExponentialMap.h>
53 #include <visp3/core/vpPoseVector.h>
54 #include <visp3/core/vpSubColVector.h>
55 #include <visp3/core/vpSubMatrix.h>
56 #include <visp3/klt/vpKltOpencv.h>
57 #include <visp3/mbt/vpMbEdgeTracker.h>
58 #include <visp3/mbt/vpMbKltTracker.h>
59 #include <visp3/mbt/vpMbTracker.h>
60 
219 class VISP_EXPORT vpMbEdgeKltTracker : public vpMbKltTracker, public vpMbEdgeTracker
220 {
221 protected:
223  double thresholdKLT;
225  double thresholdMBT;
227  unsigned int m_maxIterKlt;
236 
237 public:
239  virtual ~vpMbEdgeKltTracker();
240 
241  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
242  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
243  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
244  const vpColor &col, const unsigned int thickness = 1, const bool displayFullModel = false);
245 
246  virtual inline vpColVector getError() const { return m_error_hybrid; }
247 
248  virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int width, unsigned int height,
249  const vpHomogeneousMatrix &cMo,
250  const vpCameraParameters &cam,
251  const bool displayFullModel=false);
252 
253  virtual inline vpColVector getRobustWeights() const { return m_w_hybrid; }
254 
260  virtual inline double getNearClippingDistance() const { return vpMbKltTracker::getNearClippingDistance(); }
261 
262  virtual void loadConfigFile(const std::string &configFile);
263 
264  void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_,
265  const bool verbose = false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix());
266  void resetTracker();
267 
268  virtual void setCameraParameters(const vpCameraParameters &cam);
269 
277  virtual void setClipping(const unsigned int &flags) { vpMbEdgeTracker::setClipping(flags); }
278 
284  virtual void setFarClippingDistance(const double &dist) { vpMbEdgeTracker::setFarClippingDistance(dist); }
285 
291  virtual void setNearClippingDistance(const double &dist) { vpMbEdgeTracker::setNearClippingDistance(dist); }
292 
301  virtual void setOgreVisibilityTest(const bool &v)
302  {
304 #ifdef VISP_HAVE_OGRE
305  faces.getOgreContext()->setWindowName("MBT Hybrid");
306 #endif
307  }
308 
314  virtual void setScanLineVisibilityTest(const bool &v)
315  {
318  }
319 
320  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cdMo);
321  virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cdMo);
329 
330  virtual void testTracking() {}
331  virtual void track(const vpImage<unsigned char> &I);
332  virtual void track(const vpImage<vpRGBa> &I_color);
333 
334 protected:
335  virtual void computeVVS(const vpImage<unsigned char> &I, const unsigned int &nbInfos, unsigned int &nbrow,
336  const unsigned int lvl = 0);
337  virtual void computeVVSInit();
341 
342  virtual void init(const vpImage<unsigned char> &I);
343  virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, const double r, const int idFace = 0,
344  const std::string &name = "");
345  virtual void initCylinder(const vpPoint &, const vpPoint &, const double r, const int idFace,
346  const std::string &name = "");
347  virtual void initFaceFromCorners(vpMbtPolygon &polygon);
348  virtual void initFaceFromLines(vpMbtPolygon &polygon);
349  unsigned int initMbtTracking(const unsigned int level = 0);
350 
351  bool postTracking(const vpImage<unsigned char> &I, vpColVector &w_mbt, vpColVector &w_klt,
352  const unsigned int lvl = 0);
353  bool postTracking(const vpImage<vpRGBa> &I_color, vpColVector &w_mbt, vpColVector &w_klt,
354  const unsigned int lvl = 0);
355  void postTrackingMbt(vpColVector &w, const unsigned int level = 0);
356 
357  unsigned int trackFirstLoop(const vpImage<unsigned char> &I, vpColVector &factor, const unsigned int lvl = 0);
358  void trackSecondLoop(const vpImage<unsigned char> &I, vpMatrix &L, vpColVector &_error, vpHomogeneousMatrix &cMo,
359  const unsigned int lvl = 0);
360 };
361 
362 #endif
363 
364 #endif // VISP_HAVE_OPENCV
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
virtual void setScanLineVisibilityTest(const bool &v)
virtual double getNearClippingDistance() const
virtual vpColVector getRobustWeights() const
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
virtual void setScanLineVisibilityTest(const bool &v)
Implementation of an homogeneous matrix and operations on such kind of matrices.
virtual void init(const vpImage< unsigned char > &I)
virtual void track(const vpImage< unsigned char > &I)
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
unsigned int m_maxIterKlt
The maximum iteration of the virtual visual servoing stage.
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
double thresholdKLT
The threshold used in the robust estimation of KLT.
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo_, const bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void setClipping(const unsigned int &flags)
Make the complete tracking of an object by using its CAD model.
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
vpColVector m_w_hybrid
Robust weights.
virtual void setCameraParameters(const vpCameraParameters &camera)
void computeVVS(const vpImage< unsigned char > &_I, const unsigned int lvl)
void loadConfigFile(const std::string &configFile)
vpColVector w_mbt
Robust weights for Edge.
virtual void setFarClippingDistance(const double &dist)
Class that defines what is a point.
Definition: vpPoint.h:58
virtual void setNearClippingDistance(const double &dist)
virtual void setOgreVisibilityTest(const bool &v)
virtual void setScanLineVisibilityTest(const bool &v)
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:66
virtual vpColVector getError() const
virtual void setProjectionErrorComputation(const bool &flag)
vpColVector w_klt
Robust weights for KLT.
Generic class defining intrinsic camera parameters.
unsigned int initMbtTracking(unsigned int &nberrors_lines, unsigned int &nberrors_cylinders, unsigned int &nberrors_circles)
virtual void computeVVSInteractionMatrixAndResidu()
virtual void setFarClippingDistance(const double &dist)
Model based tracker using only KLT.
virtual void initFaceFromLines(vpMbtPolygon &polygon)
Hybrid tracker based on moving-edges and keypoints tracked using KLT tracker.
virtual void testTracking()
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, const double radius, const int idFace=0, const std::string &name="")
virtual void setOgreVisibilityTest(const bool &v)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
vpColVector m_error_hybrid
(s - s*)
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, const double radius, const int idFace=0, const std::string &name="")
virtual void computeVVSPoseEstimation(const bool isoJoIdentity_, const unsigned int iter, vpMatrix &L, vpMatrix &LTL, vpColVector &R, const vpColVector &error, vpColVector &error_prev, vpColVector &LTR, double &mu, vpColVector &v, const vpColVector *const w=NULL, vpColVector *const m_w_prev=NULL)
virtual void computeCovarianceMatrixVVS(const bool isoJoIdentity_, const vpColVector &w_true, const vpHomogeneousMatrix &cMoPrev, const vpMatrix &L_true, const vpMatrix &LVJ_true, const vpColVector &error)
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)
virtual void computeVVSInit()
virtual double getNearClippingDistance() const
Definition: vpMbTracker.h:371
virtual void setClipping(const unsigned int &flags)
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const bool displayFullModel=false)
double thresholdMBT
The threshold used in the robust estimation of MBT.
virtual void setNearClippingDistance(const double &dist)
virtual void setProjectionErrorComputation(const bool &flag)
Definition: vpMbTracker.h:580