Visual Servoing Platform  version 3.6.1 under development (2024-03-28)
vpMbEdgeKltTracker.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See https://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Hybrid tracker based on edges (vpMbt) and points of interests (KLT)
32  */
33 
39 #ifndef _vpMbEdgeKltTracker_h_
40 #define _vpMbEdgeKltTracker_h_
41 
42 #include <visp3/core/vpConfig.h>
43 
44 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
45 
46 #include <visp3/core/vpExponentialMap.h>
47 #include <visp3/core/vpPoseVector.h>
48 #include <visp3/core/vpSubColVector.h>
49 #include <visp3/core/vpSubMatrix.h>
50 #include <visp3/klt/vpKltOpencv.h>
51 #include <visp3/mbt/vpMbEdgeTracker.h>
52 #include <visp3/mbt/vpMbKltTracker.h>
53 #include <visp3/mbt/vpMbTracker.h>
54 
206 class VISP_EXPORT vpMbEdgeKltTracker :
207 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
208  public vpMbKltTracker,
209 #endif
210  public vpMbEdgeTracker
211 {
212 protected:
218  unsigned int m_maxIterKlt;
227 
228 public:
230  virtual ~vpMbEdgeKltTracker();
231 
232  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
233  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override;
234  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
235  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override;
236 
237  virtual inline vpColVector getError() const vp_override { return m_error_hybrid; }
238 
239  virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int width, unsigned int height,
240  const vpHomogeneousMatrix &cMo,
241  const vpCameraParameters &cam,
242  bool displayFullModel = false) vp_override;
243 
244  virtual inline vpColVector getRobustWeights() const vp_override { return m_w_hybrid; }
245 
251  virtual inline double getNearClippingDistance() const vp_override { return vpMbKltTracker::getNearClippingDistance(); }
252 
253  virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override;
254 
255  void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo,
256  bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix()) vp_override;
257  void resetTracker() vp_override;
258 
259  virtual void setCameraParameters(const vpCameraParameters &cam) vp_override;
260 
268  virtual void setClipping(const unsigned int &flags) vp_override { vpMbEdgeTracker::setClipping(flags); }
269 
275  virtual void setFarClippingDistance(const double &dist) vp_override { vpMbEdgeTracker::setFarClippingDistance(dist); }
276 
282  virtual void setNearClippingDistance(const double &dist) vp_override { vpMbEdgeTracker::setNearClippingDistance(dist); }
283 
292  virtual void setOgreVisibilityTest(const bool &v) vp_override
293  {
295 #ifdef VISP_HAVE_OGRE
296  faces.getOgreContext()->setWindowName("MBT Hybrid");
297 #endif
298  }
299 
305  virtual void setScanLineVisibilityTest(const bool &v) vp_override
306  {
309  }
310 
311  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cdMo) vp_override;
312  virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cdMo) vp_override;
313 
320  virtual void setProjectionErrorComputation(const bool &flag) vp_override
321  {
323  }
324 
325  virtual void testTracking() vp_override { }
326  virtual void track(const vpImage<unsigned char> &I) vp_override;
327  virtual void track(const vpImage<vpRGBa> &I_color) vp_override;
328 
329 protected:
330  virtual void computeVVS(const vpImage<unsigned char> &I, const unsigned int &nbInfos, unsigned int &nbrow,
331  unsigned int lvl = 0, double *edge_residual = nullptr, double *klt_residual = nullptr);
332  virtual void computeVVSInit() vp_override;
333  virtual void computeVVSInteractionMatrixAndResidu() vp_override;
334  using vpMbTracker::computeCovarianceMatrixVVS;
335  using vpMbTracker::computeVVSPoseEstimation;
336 
337  virtual void init(const vpImage<unsigned char> &I) vp_override;
338  virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, double r, int idFace = 0,
339  const std::string &name = "") vp_override;
340  virtual void initCylinder(const vpPoint &, const vpPoint &, double r, int idFace, const std::string &name = "") vp_override;
341  virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override;
342  virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override;
343  unsigned int initMbtTracking(unsigned int level = 0);
344 
345  bool postTracking(const vpImage<unsigned char> &I, vpColVector &w_mbt, vpColVector &w_klt, unsigned int lvl = 0);
346  bool postTracking(const vpImage<vpRGBa> &I_color, vpColVector &w_mbt, vpColVector &w_klt, unsigned int lvl = 0);
347  void postTrackingMbt(vpColVector &w, unsigned int level = 0);
348 
349  unsigned int trackFirstLoop(const vpImage<unsigned char> &I, vpColVector &factor, unsigned int lvl = 0);
350  void trackSecondLoop(const vpImage<unsigned char> &I, vpMatrix &L, vpColVector &_error,
351  const vpHomogeneousMatrix &cMo, unsigned int lvl = 0);
352 };
353 
354 #endif
355 
356 #endif // VISP_HAVE_OPENCV
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
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:146
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() vp_override
virtual void setOgreVisibilityTest(const bool &v) vp_override
virtual void setProjectionErrorComputation(const bool &flag) vp_override
virtual void setScanLineVisibilityTest(const bool &v) vp_override
vpColVector m_w_mbt
Robust weights for Edge.
virtual double getNearClippingDistance() const vp_override
virtual void setNearClippingDistance(const double &dist) vp_override
vpColVector m_error_hybrid
(s - s*)
virtual void setFarClippingDistance(const double &dist) vp_override
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 setNearClippingDistance(const double &dist) vp_override
virtual void setFarClippingDistance(const double &dist) vp_override
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) vp_override
virtual void track(const vpImage< unsigned char > &I) vp_override
virtual void setClipping(const unsigned int &flags) vp_override
virtual void setScanLineVisibilityTest(const bool &v) vp_override
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false) vp_override
virtual void computeVVSInit() vp_override
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false) vp_override
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) vp_override
Model based tracker using only KLT.
virtual void setScanLineVisibilityTest(const bool &v) vp_override
Main methods for a model-based tracker.
Definition: vpMbTracker.h:105
virtual double getNearClippingDistance() const
Definition: vpMbTracker.h:375
virtual void setOgreVisibilityTest(const bool &v)
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:58
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:77
Definition: vpRGBa.h:61