Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRBFeatureTracker.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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_FEATURE_TRACKER_H
36#define VP_RB_FEATURE_TRACKER_H
37
38#include <array>
39
40#include <visp3/core/vpConfig.h>
41#include <visp3/core/vpMatrix.h>
42#include <visp3/core/vpColVector.h>
43#include <visp3/core/vpMatrixException.h>
44#include <visp3/core/vpImage.h>
45#include <visp3/core/vpCameraParameters.h>
46#include <visp3/core/vpRect.h>
47#include <visp3/visual_features/vpFeatureThetaU.h>
48
49#include <visp3/rbt/vpRBFeatureTrackerInput.h>
50#include <visp3/rbt/vpRBSilhouettePoint.h>
51#include <visp3/rbt/vpTemporalWeighting.h>
52
53#if defined(VISP_HAVE_NLOHMANN_JSON)
54#include VISP_NLOHMANN_JSON(json.hpp)
55#endif
56
70class VISP_EXPORT vpRBFeatureTracker
71{
72public:
73
75
76 virtual ~vpRBFeatureTracker() = default;
77
83
88 unsigned getNumFeatures() const { return m_numFeatures; }
89
94
101 virtual bool requiresRGB() const = 0;
102
107 virtual bool requiresDepth() const = 0;
108
112 virtual bool requiresSilhouetteCandidates() const = 0;
116
121
126 virtual void onTrackingIterStart(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo) = 0;
127
132 virtual void onTrackingIterEnd(const vpHomogeneousMatrix &cMo) = 0;
133
138 virtual void extractFeatures(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo) = 0;
139
143 virtual void trackFeatures(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo) = 0;
144
145 virtual void initVVS(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo) = 0;
146 virtual void computeVVSIter(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo, unsigned int iteration) = 0;
147
152 virtual void reset() { }
153
157
162
164 void setFeaturesShouldBeDisplayed(bool enableDisplay) { m_enableDisplay = enableDisplay; }
165
166 virtual void display(
167 const vpCameraParameters &cam,
168 const vpImage<unsigned char> &I,
169 const vpImage<vpRGBa> &IRGB,
170 const vpImage<unsigned char> &depth) const = 0;
171
175
176
186 virtual const vpMatrix getCovariance() const { return m_cov; }
192 virtual void updateCovariance(const double lambda);
196
200 bool vvsHasConverged() const { return m_vvsConverged; }
201
207 virtual double getVVSTrackerWeight(double optimizationProgress) const { return m_weighting->weight(optimizationProgress) / m_numFeatures; }
208 const std::shared_ptr<vpTemporalWeighting> getTemporalTrackerWeight() const { return m_weighting; }
209 void setTrackerWeight(double weight) { m_weighting = std::make_shared<vpFixedTemporalWeighting>(weight); }
210 void setTrackerWeight(const std::shared_ptr<vpTemporalWeighting> &weight) { m_weighting = weight; }
211
215 virtual vpMatrix getLTL() const { return m_LTL; }
216
220 virtual vpColVector getLTR() const { return m_LTR; }
221
227
228#if defined(VISP_HAVE_NLOHMANN_JSON)
229 virtual void loadJsonConfiguration(const nlohmann::json &j)
230 {
232 m_enableDisplay = j.value("display", m_enableDisplay);
233 const std::array<bool, 6> allDofs { true, true, true, true, true, true };
234 setEstimatedDofs(j.value("dofs", allDofs));
235 }
236#endif
237
238 void setComputeJacobianObjectSpace(bool inObjectSpace)
239 {
240 m_jacobianInObjectSpace = inObjectSpace;
241 }
242
243 static void computeJTR(const vpMatrix &interaction, const vpColVector &error, vpColVector &JTR);
244 static vpMatrix computeCovarianceMatrix(const vpMatrix &A, const vpColVector &b, const vpMatrix &W);
245
246 bool hasIgnoredDofs() const
247 {
248 for (unsigned int i = 0; i < m_estimatedDofs.size(); ++i) {
249 if (!m_estimatedDofs[i]) {
250 return true;
251 }
252 }
253 return false;
254 }
255 void setEstimatedDofs(const std::array<bool, 6> &dofs)
256 {
257 m_estimatedDofs = dofs;
258 m_oJo = computeoJo();
259 }
260
261
263 {
264
265 for (unsigned int i = 0; i < m_L.getRows(); ++i) {
268 for (unsigned int dof = 0; dof < 6; ++dof) {
269 m_L[i][dof] *= m_weights[i];
270 }
271 }
273 vpVelocityTwistMatrix cVo(cMo);
274 vpMatrix cVooJo = cVo * m_oJo;
275 m_L = m_L * cVooJo;
276 }
277
278 m_LTL = m_L.AtA();
280 }
281
282protected:
283
285 {
286 vpMatrix oJo(6, 6, 0);
287 for (unsigned int i = 0; i < 6; ++i) {
288 if (m_estimatedDofs[i]) {
289 oJo[i][i] = 1;
290 }
291 }
292 return oJo;
293 }
294
295
296
297
303
307
308
309 unsigned m_numFeatures;
310 std::shared_ptr<vpTemporalWeighting> m_weighting;
311
313
315 std::array<bool, 6> m_estimatedDofs;
318};
319
320END_VISP_NAMESPACE
321
322#endif
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
All the data related to a single tracking frame. This contains both the input data (from a real camer...
virtual void onTrackingIterEnd(const vpHomogeneousMatrix &cMo)=0
Method called after the tracking iteration has finished.
void updateOptimizerTerms(const vpHomogeneousMatrix &cMo)
virtual bool requiresDepth() const =0
Whether this tracker requires depth image to extract features.
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 const vpMatrix getCovariance() const
Retrieve the 6 x 6 pose covariance matrix, computed from the weights associated to each feature.
virtual vpColVector getLTR() const
Get the right-side term of the Gauss-Newton optimization term.
vpColVector m_weights
Weighted VS error.
unsigned getNumFeatures() const
Return the type of feature that is used by this tracker.
void setTrackerWeight(double weight)
void setTrackerWeight(const std::shared_ptr< vpTemporalWeighting > &weight)
virtual void trackFeatures(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo)=0
Track the features.
virtual bool requiresSilhouetteCandidates() const =0
Whether this tracker requires Silhouette candidates.
virtual void onTrackingIterStart(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo)=0
Method called when starting a tracking iteration.
std::shared_ptr< vpTemporalWeighting > m_weighting
Number of considered features.
virtual ~vpRBFeatureTracker()=default
bool m_jacobianInObjectSpace
Matrix representation of the estimated DOFS.
virtual void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpImage< vpRGBa > &IRGB, const vpImage< unsigned char > &depth) const =0
vpMatrix m_LTL
Error jacobian (In VS terms, the interaction matrix).
virtual void reset()
Resets feature state. Can be called when the object changes or is lost, Ensuring that prior data does...
const vpColVector & getWeightedError() const
Get a weighted version of the error vector. This should not include the userVVSWeight,...
bool m_enableDisplay
Whether VVS has converged, should be updated every VVS iteration.
bool featuresShouldBeDisplayed() const
virtual vpMatrix getLTL() const
Get the left-side term of the Gauss-Newton optimization term.
virtual void loadJsonConfiguration(const nlohmann::json &j)
vpColVector m_covWeightDiag
Covariance matrix.
vpMatrix computeoJo() const
const std::shared_ptr< vpTemporalWeighting > getTemporalTrackerWeight() const
void setFeaturesShouldBeDisplayed(bool enableDisplay)
virtual double getVVSTrackerWeight(double optimizationProgress) const
Get the importance of this tracker in the optimization step. The default computation is the following...
vpColVector m_LTR
Left side of the Gauss newton minimization.
virtual void initVVS(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, const vpHomogeneousMatrix &cMo)=0
std::array< bool, 6 > m_estimatedDofs
Whether the tracked features should be displayed.
void setEstimatedDofs(const std::array< bool, 6 > &dofs)
static void computeJTR(const vpMatrix &interaction, const vpColVector &error, vpColVector &JTR)
bool m_vvsConverged
User-defined weight for this specific type of feature.
unsigned m_numFeatures
Error weights.
virtual void computeVVSIter(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo, unsigned int iteration)=0
vpColVector m_weighted_error
Raw VS Error vector.
virtual bool requiresRGB() const =0
Whether this tracker requires RGB image to extract features.
void setComputeJacobianObjectSpace(bool inObjectSpace)
vpMatrix m_cov
Right side of the Gauss Newton minimization.
static std::shared_ptr< vpTemporalWeighting > parseTemporalWeighting(const nlohmann::json &j)