Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
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 
55 BEGIN_VISP_NAMESPACE
211 class VISP_EXPORT vpMbEdgeKltTracker :
212 #if defined(VISP_HAVE_MODULE_KLT) && defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && defined(HAVE_OPENCV_VIDEO)
213  public vpMbKltTracker,
214 #endif
215  public vpMbEdgeTracker
216 {
217 protected:
219  double m_thresholdKLT;
221  double m_thresholdMBT;
223  unsigned int m_maxIterKlt;
225  vpColVector m_w_mbt;
227  vpColVector m_w_klt;
229  vpColVector m_error_hybrid;
231  vpColVector m_w_hybrid;
232 
233 public:
234  vpMbEdgeKltTracker();
235  virtual ~vpMbEdgeKltTracker();
236 
237  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
238  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE;
239  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
240  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) VP_OVERRIDE;
241 
242  virtual inline vpColVector getError() const VP_OVERRIDE { return m_error_hybrid; }
243 
244  virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int width, unsigned int height,
245  const vpHomogeneousMatrix &cMo,
246  const vpCameraParameters &cam,
247  bool displayFullModel = false) VP_OVERRIDE;
248 
249  virtual inline vpColVector getRobustWeights() const VP_OVERRIDE { return m_w_hybrid; }
250 
256  virtual inline double getNearClippingDistance() const VP_OVERRIDE { return vpMbKltTracker::getNearClippingDistance(); }
257 
258  virtual void loadConfigFile(const std::string &configFile, bool verbose = true) VP_OVERRIDE;
259 
260  void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo,
261  bool verbose = false, const vpHomogeneousMatrix &T = vpHomogeneousMatrix()) VP_OVERRIDE;
262  void resetTracker() VP_OVERRIDE;
263 
264  virtual void setCameraParameters(const vpCameraParameters &cam) VP_OVERRIDE;
265 
273  virtual void setClipping(const unsigned int &flags) VP_OVERRIDE { vpMbEdgeTracker::setClipping(flags); }
274 
280  virtual void setFarClippingDistance(const double &dist) VP_OVERRIDE { vpMbEdgeTracker::setFarClippingDistance(dist); }
281 
287  virtual void setNearClippingDistance(const double &dist) VP_OVERRIDE { vpMbEdgeTracker::setNearClippingDistance(dist); }
288 
297  virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE
298  {
300 #ifdef VISP_HAVE_OGRE
301  faces.getOgreContext()->setWindowName("MBT Hybrid");
302 #endif
303  }
304 
310  virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE
311  {
313  vpMbKltTracker::setScanLineVisibilityTest(v);
314  }
315 
316  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE;
317  virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE;
318 
325  virtual void setProjectionErrorComputation(const bool &flag) VP_OVERRIDE
326  {
328  }
329 
330  virtual void testTracking() VP_OVERRIDE { }
331  virtual void track(const vpImage<unsigned char> &I) VP_OVERRIDE;
332  virtual void track(const vpImage<vpRGBa> &I_color) VP_OVERRIDE;
333 
334 protected:
335  virtual void computeVVS(const vpImage<unsigned char> &I, const unsigned int &nbInfos, unsigned int &nbrow,
336  unsigned int lvl = 0, double *edge_residual = nullptr, double *klt_residual = nullptr);
337  virtual void computeVVSInit() VP_OVERRIDE;
338  virtual void computeVVSInteractionMatrixAndResidu() VP_OVERRIDE;
339  using vpMbTracker::computeCovarianceMatrixVVS;
340  using vpMbTracker::computeVVSPoseEstimation;
341 
342  virtual void init(const vpImage<unsigned char> &I) VP_OVERRIDE;
343  virtual void initCircle(const vpPoint &, const vpPoint &, const vpPoint &, double r, int idFace = 0,
344  const std::string &name = "") VP_OVERRIDE;
345  virtual void initCylinder(const vpPoint &, const vpPoint &, double r, int idFace, const std::string &name = "") VP_OVERRIDE;
346  virtual void initFaceFromCorners(vpMbtPolygon &polygon) VP_OVERRIDE;
347  virtual void initFaceFromLines(vpMbtPolygon &polygon) VP_OVERRIDE;
348  unsigned int initMbtTracking(unsigned int level = 0);
349 
350  bool postTracking(const vpImage<unsigned char> &I, vpColVector &w_mbt, vpColVector &w_klt, unsigned int lvl = 0);
351  bool postTracking(const vpImage<vpRGBa> &I_color, vpColVector &w_mbt, vpColVector &w_klt, unsigned int lvl = 0);
352  void postTrackingMbt(vpColVector &w, unsigned int level = 0);
353 
354  unsigned int trackFirstLoop(const vpImage<unsigned char> &I, vpColVector &factor, unsigned int lvl = 0);
355  void trackSecondLoop(const vpImage<unsigned char> &I, vpMatrix &L, vpColVector &_error,
356  const vpHomogeneousMatrix &cMo, unsigned int lvl = 0);
357 };
358 END_VISP_NAMESPACE
359 #endif
360 
361 #endif // VISP_HAVE_OPENCV
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Make the complete tracking of an object by using its CAD model.
void computeVVS(const vpImage< unsigned char > &_I, unsigned int lvl)
virtual void setScanLineVisibilityTest(const bool &v) VP_OVERRIDE
virtual void testTracking() VP_OVERRIDE
virtual void setNearClippingDistance(const double &dist) VP_OVERRIDE
virtual void track(const vpImage< unsigned char > &I) 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 computeVVSInit() VP_OVERRIDE
virtual void setFarClippingDistance(const double &dist) VP_OVERRIDE
virtual void setOgreVisibilityTest(const bool &v) VP_OVERRIDE
virtual void setClipping(const unsigned int &flags) 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 setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo) VP_OVERRIDE
virtual void loadConfigFile(const std::string &configFile, bool verbose=true) VP_OVERRIDE
Main methods for a model-based tracker.
Definition: vpMbTracker.h:107
virtual double getNearClippingDistance() const
Definition: vpMbTracker.h:377
virtual void setOgreVisibilityTest(const bool &v)
virtual void setProjectionErrorComputation(const bool &flag)
Definition: vpMbTracker.h:587
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:60
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:79
Definition: vpRGBa.h:65