Visual Servoing Platform  version 3.6.1 under development (2025-01-11)
vpRBSilhouetteMeTracker.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 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 
35 #ifndef VP_RB_SILHOUETTE_ME_TRACKER_H
36 #define VP_RB_SILHOUETTE_ME_TRACKER_H
37 
38 #include <visp3/rbt/vpRBFeatureTracker.h>
39 #include <visp3/rbt/vpRBSilhouetteControlPoint.h>
40 #include <visp3/core/vpRobust.h>
41 
42 BEGIN_VISP_NAMESPACE
48 class VISP_EXPORT vpRBSilhouetteMeTracker : public vpRBFeatureTracker
49 {
50 public:
51 
53  vpRBFeatureTracker(), m_me(), m_numCandidates(1), m_robustMadMin(1.0), m_globalVVSConvergenceThreshold(1.0),
54  m_singlePointConvergedThresholdPixels(3), m_useMask(false), m_minMaskConfidence(0.f)
55  { }
56 
57  virtual ~vpRBSilhouetteMeTracker() = default;
58 
59  bool requiresRGB() const VP_OVERRIDE { return false; }
60 
61  bool requiresDepth() const VP_OVERRIDE { return false; }
62 
63  bool requiresSilhouetteCandidates() const VP_OVERRIDE { return true; }
64 
65  void setMovingEdge(const vpMe &me) { m_me = me; }
66 
67  void onTrackingIterStart() VP_OVERRIDE
68  {
69  m_controlPoints.clear();
70  }
71 
72  void onTrackingIterEnd() VP_OVERRIDE { }
73 
77  void extractFeatures(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo) VP_OVERRIDE;
78 
79  void trackFeatures(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo) VP_OVERRIDE;
80 
81  void initVVS(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo) VP_OVERRIDE;
82 
83  void computeVVSIter(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo, unsigned int iteration) VP_OVERRIDE;
84 
85  void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpImage<vpRGBa> &IRGB, const vpImage<unsigned char> &depth) const VP_OVERRIDE;
86 
91  const vpMe &getMe() const { return m_me; }
92  vpMe &getMe() { return m_me; }
93 
94  unsigned int getNumCandidates() const { return m_numCandidates; }
95  void setNumCandidates(unsigned int candidates)
96  {
97  if (candidates == 0) {
98  throw vpException(vpException::badValue, "Cannot set a number of candidates equal to zero");
99  }
100  m_numCandidates = candidates;
101  }
102 
103  double getMinRobustThreshold() const { return m_robustMadMin; }
104  void setMinRobustThreshold(double threshold)
105  {
106  if (threshold < 0) {
107  throw vpException(vpException::badValue, "Robust M estimator min threshold should be greater or equal to 0.");
108  }
109  m_robustMadMin = threshold;
110  }
111 
116  bool shouldUseMask() const { return m_useMask; }
117  void setShouldUseMask(bool useMask) { m_useMask = useMask; }
118 
124  float getMinimumMaskConfidence() const { return m_minMaskConfidence; }
125  void setMinimumMaskConfidence(float confidence)
126  {
127  if (confidence > 1.f || confidence < 0.f) {
128  throw vpException(vpException::badValue, "Mask confidence should be between 0 and 1");
129  }
130  m_minMaskConfidence = confidence;
131  }
132 
133  double getSinglePointConvergenceThreshold() const { return m_singlePointConvergedThresholdPixels; }
134  void setSinglePointConvergenceThreshold(double threshold)
135  {
136  if (threshold < 0.0) {
137  throw vpException(vpException::badValue, "Convergence threshold should be null or positive");
138  }
139  m_singlePointConvergedThresholdPixels = threshold;
140  }
141 
142  double getGlobalConvergenceMinimumRatio() const { return m_globalVVSConvergenceThreshold; }
143  void setGlobalConvergenceMinimumRatio(double threshold)
144  {
145  if (threshold < 0.0 || threshold > 1.0) {
146  throw vpException(vpException::badValue, "Minimum converged ratio be between 0 and 1");
147  }
148  m_globalVVSConvergenceThreshold = threshold;
149  }
150 
151 #if defined(VISP_HAVE_NLOHMANN_JSON)
152  virtual void loadJsonConfiguration(const nlohmann::json &j) VP_OVERRIDE
153  {
155  setNumCandidates(j.value("numCandidates", m_numCandidates));
156  setSinglePointConvergenceThreshold(j.value("convergencePixelThreshold", m_singlePointConvergedThresholdPixels));
157  setGlobalConvergenceMinimumRatio(j.value("convergenceRatio", m_globalVVSConvergenceThreshold));
158  m_me = j.value("movingEdge", m_me);
159  setShouldUseMask(j.value("useMask", m_useMask));
160  setMinimumMaskConfidence(j.value("minMaskConfidence", m_minMaskConfidence));
161  // m_me.setThresholdMarginRatio(-1.0);
162  // m_me.setMinThreshold(-1.0);
163  }
164 #endif
165 
171 private:
172 
173  std::vector<vpRBSilhouetteControlPoint> m_controlPoints;
174  vpMe m_me;
175  unsigned int m_numCandidates;
176  vpRobust m_robust;
177  double m_robustMadMin;
178  double m_globalVVSConvergenceThreshold;
179  double m_singlePointConvergedThresholdPixels;
180  bool m_useMask;
181  float m_minMaskConfidence;
182 };
183 
184 END_VISP_NAMESPACE
185 
186 #endif
Generic class defining intrinsic camera parameters.
error that can be emitted by ViSP classes.
Definition: vpException.h:60
@ badValue
Used to indicate that a value is not in the allowed range.
Definition: vpException.h:73
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition: vpMe.h:134
All the data related to a single tracking frame. This contains both the input data (from a real camer...
A base class for all features that can be used and tracked in the vpRBTracker.
virtual void extractFeatures(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo)=0
Extract features from the frame data and the current pose estimate.
virtual void trackFeatures(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo)=0
Track the features.
virtual void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpImage< vpRGBa > &IRGB, const vpImage< unsigned char > &depth) const =0
virtual void loadJsonConfiguration(const nlohmann::json &j)
virtual void initVVS(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo)=0
virtual void computeVVSIter(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo, unsigned int iteration)=0
Moving edge feature tracking from depth-extracted object contours.
bool requiresRGB() const VP_OVERRIDE
Whether this tracker requires RGB image to extract features.
virtual ~vpRBSilhouetteMeTracker()=default
virtual void loadJsonConfiguration(const nlohmann::json &j) VP_OVERRIDE
void setNumCandidates(unsigned int candidates)
double getSinglePointConvergenceThreshold() const
void setMinimumMaskConfidence(float confidence)
float getMinimumMaskConfidence() const
Returns the minimum mask confidence that a pixel linked to depth point should have if it should be ke...
void setSinglePointConvergenceThreshold(double threshold)
bool shouldUseMask() const
Returns whether the tracking algorithm should filter out points that are unlikely to be on the object...
void onTrackingIterEnd() VP_OVERRIDE
Method called after the tracking iteration has finished.
void onTrackingIterStart() VP_OVERRIDE
Method called when starting a tracking iteration.
double getGlobalConvergenceMinimumRatio() const
void setGlobalConvergenceMinimumRatio(double threshold)
void setMovingEdge(const vpMe &me)
bool requiresSilhouetteCandidates() const VP_OVERRIDE
Whether this tracker requires Silhouette candidates.
void setShouldUseMask(bool useMask)
unsigned int getNumCandidates() const
void setMinRobustThreshold(double threshold)
bool requiresDepth() const VP_OVERRIDE
Whether this tracker requires depth image to extract features.
Contains an M-estimator and various influence function.
Definition: vpRobust.h:84