Visual Servoing Platform  version 3.6.1 under development (2024-04-18)
vpMbDepthDenseTracker.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  * Model-based tracker using depth dense features.
32  */
33 
34 #ifndef _vpMbDepthDenseTracker_h_
35 #define _vpMbDepthDenseTracker_h_
36 
37 #include <visp3/core/vpPlane.h>
38 #include <visp3/mbt/vpMbTracker.h>
39 #include <visp3/mbt/vpMbtFaceDepthDense.h>
40 #include <visp3/mbt/vpMbtTukeyEstimator.h>
41 
42 #if DEBUG_DISPLAY_DEPTH_DENSE
43 #include <visp3/core/vpDisplay.h>
44 #endif
45 
46 class VISP_EXPORT vpMbDepthDenseTracker : public virtual vpMbTracker
47 {
48 public:
50  virtual ~vpMbDepthDenseTracker() vp_override;
51 
52  virtual void display(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
53  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override;
54 
55  virtual void display(const vpImage<vpRGBa> &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam,
56  const vpColor &col, unsigned int thickness = 1, bool displayFullModel = false) vp_override;
57 
58  virtual inline vpColVector getError() const vp_override { return m_error_depthDense; }
59 
60  virtual std::vector<std::vector<double> > getModelForDisplay(unsigned int width, unsigned int height,
61  const vpHomogeneousMatrix &cMo,
62  const vpCameraParameters &cam,
63  bool displayFullModel = false) vp_override;
64 
65  virtual inline vpColVector getRobustWeights() const vp_override { return m_w_depthDense; }
66 
67  virtual void init(const vpImage<unsigned char> &I) vp_override;
68 
69  virtual void loadConfigFile(const std::string &configFile, bool verbose = true) vp_override;
70 
71  void reInitModel(const vpImage<unsigned char> &I, const std::string &cad_name, const vpHomogeneousMatrix &cMo,
72  bool verbose = false);
73 #if defined(VISP_HAVE_PCL)
74  void reInitModel(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud, const std::string &cad_name,
75  const vpHomogeneousMatrix &cMo, bool verbose = false);
76 #endif
77 
78  virtual void resetTracker() vp_override;
79 
80  virtual void setCameraParameters(const vpCameraParameters &camera) vp_override;
81 
82  virtual void setDepthDenseFilteringMaxDistance(double maxDistance);
83  virtual void setDepthDenseFilteringMethod(int method);
84  virtual void setDepthDenseFilteringMinDistance(double minDistance);
85  virtual void setDepthDenseFilteringOccupancyRatio(double occupancyRatio);
86 
87  inline void setDepthDenseSamplingStep(unsigned int stepX, unsigned int stepY)
88  {
89  if (stepX == 0 || stepY == 0) {
90  std::cerr << "stepX and stepY must be greater than zero!" << std::endl;
91  return;
92  }
93 
94  m_depthDenseSamplingStepX = stepX;
95  m_depthDenseSamplingStepY = stepY;
96  }
97 
98  virtual void setOgreVisibilityTest(const bool &v) vp_override;
99 
100  virtual void setPose(const vpImage<unsigned char> &I, const vpHomogeneousMatrix &cdMo) vp_override;
101  virtual void setPose(const vpImage<vpRGBa> &I_color, const vpHomogeneousMatrix &cdMo) vp_override;
102 #ifdef VISP_HAVE_PCL
103  virtual void setPose(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud, const vpHomogeneousMatrix &cdMo);
104 #endif
105 
106  virtual void setScanLineVisibilityTest(const bool &v) vp_override;
107 
108  void setUseDepthDenseTracking(const std::string &name, const bool &useDepthDenseTracking);
109 
110  virtual void testTracking() vp_override;
111 
112  virtual void track(const vpImage<unsigned char> &) vp_override;
113  virtual void track(const vpImage<vpRGBa> &) vp_override;
114 #ifdef VISP_HAVE_PCL
115  virtual void track(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
116 #endif
117  virtual void track(const std::vector<vpColVector> &point_cloud, unsigned int width, unsigned int height);
118 
119 protected:
123  std::vector<vpMbtFaceDepthDense *> m_depthDenseListOfActiveFaces;
127  std::vector<vpMbtFaceDepthDense *> m_depthDenseFaces;
137  vpMbtTukeyEstimator<double> m_robust_depthDense;
142 #if DEBUG_DISPLAY_DEPTH_DENSE
143  vpDisplay *m_debugDisp_depthDense;
144  vpImage<unsigned char> m_debugImage_depthDense;
145 #endif
146 
147  void addFace(vpMbtPolygon &polygon, bool alreadyClose);
148 
149  void computeVisibility(unsigned int width, unsigned int height);
150 
151  void computeVVS();
152  virtual void computeVVSInit() vp_override;
153  virtual void computeVVSInteractionMatrixAndResidu() vp_override;
154  virtual void computeVVSWeights();
155  using vpMbTracker::computeVVSWeights;
156 
157  virtual void initCircle(const vpPoint &p1, const vpPoint &p2, const vpPoint &p3, double radius, int idFace = 0,
158  const std::string &name = "") vp_override;
159 
160  virtual void initCylinder(const vpPoint &p1, const vpPoint &p2, double radius, int idFace = 0,
161  const std::string &name = "") vp_override;
162 
163  virtual void initFaceFromCorners(vpMbtPolygon &polygon) vp_override;
164 
165  virtual void initFaceFromLines(vpMbtPolygon &polygon) vp_override;
166 
167 #ifdef VISP_HAVE_PCL
168  void segmentPointCloud(const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &point_cloud);
169 #endif
170  void segmentPointCloud(const std::vector<vpColVector> &point_cloud, unsigned int width, unsigned int height);
171  void segmentPointCloud(const vpMatrix &point_cloud, unsigned int width, unsigned int height);
172 };
173 #endif
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
Class that defines generic functionalities for display.
Definition: vpDisplay.h:173
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:146
vpMbtTukeyEstimator< double > m_robust_depthDense
Tukey M-Estimator.
vpColVector m_weightedError_depthDense
Weighted error.
unsigned int m_depthDenseSamplingStepY
Sampling step in y-direction.
vpMbHiddenFaces< vpMbtPolygon > m_depthDenseHiddenFacesDisplay
Set of faces describing the object used only for display with scan line.
unsigned int m_depthDenseSamplingStepX
Sampling step in x-direction.
vpColVector m_error_depthDense
(s - s*)
vpMatrix m_L_depthDense
Interaction matrix.
std::vector< vpMbtFaceDepthDense * > m_depthDenseListOfActiveFaces
List of current active (visible and features extracted) faces.
unsigned int m_denseDepthNbFeatures
Nb features.
vpColVector m_w_depthDense
Robust weights.
virtual vpColVector getError() const vp_override
std::vector< vpMbtFaceDepthDense * > m_depthDenseFaces
List of faces.
Main methods for a model-based tracker.
Definition: vpMbTracker.h:105
virtual void track(const vpImage< unsigned char > &I)=0
virtual void resetTracker()=0
virtual void init(const vpImage< unsigned char > &I)=0
virtual std::vector< std::vector< double > > getModelForDisplay(unsigned int width, unsigned int height, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, bool displayFullModel=false)=0
virtual void setScanLineVisibilityTest(const bool &v)
Definition: vpMbTracker.h:608
virtual void setOgreVisibilityTest(const bool &v)
virtual void setPose(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cdMo)=0
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam, const vpColor &col, unsigned int thickness=1, bool displayFullModel=false)=0
virtual void computeVVSInit()=0
virtual void testTracking()=0
virtual void loadConfigFile(const std::string &configFile, bool verbose=true)
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