Visual Servoing Platform  version 3.6.0 under development (2023-09-29)
vpMbEdgeKltTracker.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 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 https://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 *****************************************************************************/
35 
41 #ifndef _vpMbEdgeKltTracker_h_
42 #define _vpMbEdgeKltTracker_h_
43 
44 #include <visp3/core/vpConfig.h>
45 
46 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
47 
48 #include <visp3/core/vpExponentialMap.h>
49 #include <visp3/core/vpPoseVector.h>
50 #include <visp3/core/vpSubColVector.h>
51 #include <visp3/core/vpSubMatrix.h>
52 #include <visp3/klt/vpKltOpencv.h>
53 #include <visp3/mbt/vpMbEdgeTracker.h>
54 #include <visp3/mbt/vpMbKltTracker.h>
55 #include <visp3/mbt/vpMbTracker.h>
56 
208 class VISP_EXPORT vpMbEdgeKltTracker :
209 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
210  public vpMbKltTracker,
211 #endif
212  public vpMbEdgeTracker
213 {
214 protected:
220  unsigned int m_maxIterKlt;
229 
230 public:
232  virtual ~vpMbEdgeKltTracker();
233 
234  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
235  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false);
236  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
237  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false);
238 
239  virtual inline vpColVector getError() const { return m_error_hybrid; }
240 
241  virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int width, unsigned int height,
242  const vpHomogeneousMatrix &cMo,
243  const vpCameraParameters &cam,
244  bool displayFullModel = false);
245 
246  virtual inline vpColVector getRobustWeights() const { return m_w_hybrid; }
247 
253  virtual inline double getNearClippingDistance() const { return vpMbKltTracker::getNearClippingDistance(); }
254 
255  virtual void loadConfigFile(const std::string &configFile, bool verbose = true);
256 
257  void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo,
258  bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix());
259  void resetTracker();
260 
261  virtual void setCameraParameters(const vpCameraParameters &cam);
262 
270  virtual void setClipping(const unsigned int &flags) { vpMbEdgeTracker::setClipping(flags); }
271 
277  virtual void setFarClippingDistance(const double &dist) { vpMbEdgeTracker::setFarClippingDistance(dist); }
278 
284  virtual void setNearClippingDistance(const double &dist) { vpMbEdgeTracker::setNearClippingDistance(dist); }
285 
294  virtual void setOgreVisibilityTest(const bool &v)
295  {
297 #ifdef VISP_HAVE_OGRE
298  faces.getOgreContext()->setWindowName("MBT Hybrid");
299 #endif
300  }
301 
307  virtual void setScanLineVisibilityTest(const bool &v)
308  {
311  }
312 
313  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cdMo);
314  virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cdMo);
322 
323  virtual void testTracking() {}
324  virtual void track(const vpImage<unsigned char> &I);
325  virtual void track(const vpImage<vpRGBa> &I_color);
326 
327 protected:
328  virtual void computeVVS(const vpImage<unsigned char> &I, const unsigned int &nbInfos, unsigned int &nbrow,
329  unsigned int lvl = 0, double *edge_residual = NULL, double *klt_residual = NULL);
330  virtual void computeVVSInit();
334 
335  virtual void init(const vpImage<unsigned char> &I);
336  virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, double r, int idFace = 0,
337  const std::string &name = "");
338  virtual void initCylinder(const vpPoint &, const vpPoint &, double r, int idFace, const std::string &name = "");
339  virtual void initFaceFromCorners(vpMbtPolygon &polygon);
340  virtual void initFaceFromLines(vpMbtPolygon &polygon);
341  unsigned int initMbtTracking(unsigned int level = 0);
342 
343  bool postTracking(const vpImage<unsigned char> &I, vpColVector &w_mbt, vpColVector &w_klt, unsigned int lvl = 0);
344  bool postTracking(const vpImage<vpRGBa> &I_color, vpColVector &w_mbt, vpColVector &w_klt, unsigned int lvl = 0);
345  void postTrackingMbt(vpColVector &w, unsigned int level = 0);
346 
347  unsigned int trackFirstLoop(const vpImage<unsigned char> &I, vpColVector &factor, unsigned int lvl = 0);
348  void trackSecondLoop(const vpImage<unsigned char> &I, vpMatrix &L, vpColVector &_error,
349  const vpHomogeneousMatrix &cMo, unsigned int lvl = 0);
350 };
351 
352 #endif
353 
354 #endif // VISP_HAVE_OPENCV
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:167
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:152
Hybrid tracker based on moving-edges and keypoints tracked using KLT tracker.
double m_thresholdKLT
The threshold used in the robust estimation of KLT.
virtual void testTracking()
virtual void setClipping(const unsigned int &flags)
virtual void setFarClippingDistance(const double &dist)
virtual double getNearClippingDistance() const
virtual void setScanLineVisibilityTest(const bool &v)
vpColVector m_w_mbt
Robust weights for Edge.
virtual void setProjectionErrorComputation(const bool &flag)
virtual vpColVector getRobustWeights() const
virtual vpColVector getError() const
vpColVector m_error_hybrid
(s - s*)
virtual void setNearClippingDistance(const double &dist)
virtual void setOgreVisibilityTest(const bool &v)
vpColVector m_w_klt
Robust weights for KLT.
double m_thresholdMBT
The threshold used in the robust estimation of MBT.
unsigned int m_maxIterKlt
The maximum iteration of the virtual visual servoing stage.
vpColVector m_w_hybrid
Robust weights.
Make the complete tracking of an object by using its CAD model.
void computeVVS(const vpImage< unsigned char > &_I, unsigned int lvl)
virtual void setCameraParameters(const vpCameraParameters &cam)
virtual void setNearClippingDistance(const double &dist)
virtual void setScanLineVisibilityTest(const bool &v)
virtual void initFaceFromLines(vpMbtPolygon &polygon)
virtual void computeVVSInit()
virtual void setFarClippingDistance(const double &dist)
virtual void reInitModel(const vpImage< unsigned char > &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo, bool verbose=false, const vpHomogeneousMatrix &T=vpHomogeneousMatrix())
virtual void computeVVSInteractionMatrixAndResidu()
virtual void track(const vpImage< unsigned char > &I)
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
virtual void setClipping(const unsigned int &flags)
virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace=0, const std::string &name="")
virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace=0, const std::string &name="")
unsigned int initMbtTracking(unsigned int &nberrors_lines, unsigned int &nberrors_cylinders, unsigned int &nberrors_circles)
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)
virtual void initFaceFromCorners(vpMbtPolygon &polygon)
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)
virtual void init(const vpImage< unsigned char > &I)
Model based tracker using only KLT.
virtual void setScanLineVisibilityTest(const bool &v)
bool postTracking(const vpImage< unsigned char > &I, vpColVector &w)
virtual double getNearClippingDistance() const
Definition: vpMbTracker.h:375
virtual void computeVVSPoseEstimation(const bool isoJoIdentity, 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 setOgreVisibilityTest(const bool &v)
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 setProjectionErrorComputation(const bool &flag)
Definition: vpMbTracker.h:585
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:65
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:77