36#ifndef VP_RB_DENSE_DEPTH_TRACKER_H
37#define VP_RB_DENSE_DEPTH_TRACKER_H
39#include <visp3/core/vpConfig.h>
40#include <visp3/core/vpImage.h>
41#include <visp3/core/vpCameraParameters.h>
42#include <visp3/core/vpPixelMeterConversion.h>
43#include <visp3/core/vpMeterPixelConversion.h>
45#include <visp3/core/vpRobust.h>
46#include <visp3/core/vpPoint.h>
47#include <visp3/core/vpHomogeneousMatrix.h>
52#include <visp3/rbt/vpRBFeatureTracker.h>
58#if defined(VISP_HAVE_NLOHMANN_JSON)
59#include VISP_NLOHMANN_JSON(json.hpp)
131 if (confidence > 1.f || confidence < 0.f) {
181 void build(
const std::vector<vpDepthPoint> &points)
183 unsigned int numPoints =
static_cast<unsigned int>(points.size());
184 std::vector<vpMatrix *> matrices = { &m_oXt, &m_oNt, &m_cXt, &m_cNt, &m_observations };
186 m->resize(3, numPoints,
false,
false);
188 m_valid.resize(numPoints);
190 for (
unsigned int i = 0; i < numPoints; ++i) {
192 for (
unsigned int j = 0; j < 3; ++j) {
193 m_oXt[j][i] = points[i].oX[j];
194 m_oNt[j][i] = points[i].objectNormal[j];
195 m_observations[j][i] = points[i].observation[j];
206 const unsigned int numPoints = m_oXt.getCols();
207 e.resize(numPoints,
false);
208 L.resize(numPoints, 6,
false,
false);
210#ifdef VISP_HAVE_OPENMP
211#pragma omp parallel for
213 for (
int i = 0; i < static_cast<int>(numPoints); ++i) {
218 for (
unsigned int j = 0; j < 3; ++j) {
222 if (m_cNt[2][i] >= 0.0) {
227 x = m_cXt[0][i] / m_cXt[2][i];
228 y = m_cXt[1][i] / m_cXt[2][i];
230 vpMeterPixelConversion::convertPointWithoutDistortion(cam, x, y, u, v);
232 if (u < 0 || v < 0 || u >= depth.getWidth() || v >= depth.getHeight()) {
236 const double Z = depth[
static_cast<unsigned int>(v)][
static_cast<unsigned int>(u)];
244 m_observations[0][i] = x * Z;
245 m_observations[1][i] = y * Z;
246 m_observations[2][i] = Z;
250 const double X = m_cXt[0][i], Y = m_cXt[1][i], Z = m_cXt[2][i];
251 const double nX = m_cNt[0][i], nY = m_cNt[1][i], nZ = m_cNt[2][i];
253 const double D = -((nX * X) + (nY * Y) + (nZ * Z));
254 double projNormal = nX * m_observations[0][i] + nY * m_observations[1][i] + nZ * m_observations[2][i];
256 e[i] = D + projNormal;
261 L[i][3] = nZ * Y - nY * Z;
262 L[i][4] = nX * Z - nZ * X;
263 L[i][5] = nY * X - nX * Y;
269 for (
unsigned int i = 0; i < numPoints; ++i) {
294 std::vector<bool> m_valid;
298#if defined(VISP_HAVE_NLOHMANN_JSON)
300#if defined(__clang__)
303# pragma clang diagnostic push
304# pragma clang diagnostic ignored "-Wexit-time-destructors"
326#if defined(__clang__)
327# pragma clang diagnostic pop
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Implementation of a matrix and operations on matrices.
static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
const vpMatrix & getPointsCamera() const
void build(const std::vector< vpDepthPoint > &points)
const vpMatrix & getNormalsObject() const
const vpMatrix & getNormalsCamera() const
void updateAndErrorAndInteractionMatrix(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const vpImage< float > &depth, vpColVector &e, vpMatrix &L)
const vpMatrix & getPointsObject() const
bool requiresSilhouetteCandidates() const VP_OVERRIDE
Whether this tracker requires Silhouette candidates.
void setMinimumMaskConfidence(float confidence)
void initVVS(const vpRBFeatureTrackerInput &, const vpRBFeatureTrackerInput &, const vpHomogeneousMatrix &) VP_OVERRIDE
void trackFeatures(const vpRBFeatureTrackerInput &, const vpRBFeatureTrackerInput &, const vpHomogeneousMatrix &) VP_OVERRIDE
Track the features.
bool requiresRGB() const VP_OVERRIDE
Whether this tracker requires RGB image to extract features.
vpDepthPointSet m_depthPointSet
unsigned int m_maxFeatures
virtual void loadJsonConfiguration(const nlohmann::json &j) VP_OVERRIDE
unsigned int getStep() const
void setMaxNumFeatures(unsigned int num)
void setStep(unsigned int step)
bool shouldUseMask() const
Returns whether the tracking algorithm should filter out points that are unlikely to be on the object...
bool requiresDepth() const VP_OVERRIDE
Whether this tracker requires depth image to extract features.
std::vector< vpDepthPoint > m_depthPoints
float getMinimumMaskConfidence() const
Returns the minimum mask confidence that a pixel linked to depth point should have if it should be ke...
unsigned int getMaxNumFeatures() const
float m_minMaskConfidence
NLOHMANN_JSON_SERIALIZE_ENUM(vpRBDenseDepthTracker::vpDisplayType, { {vpRBDenseDepthTracker::vpDisplayType::DT_INVALID, nullptr}, {vpRBDenseDepthTracker::vpDisplayType::DT_SIMPLE, "simple"}, {vpRBDenseDepthTracker::vpDisplayType::DT_WEIGHT, "weight"}, {vpRBDenseDepthTracker::vpDisplayType::DT_ERROR, "error"}, {vpRBDenseDepthTracker::vpDisplayType::DT_WEIGHT_AND_ERROR, "weightAndError"} })
void onTrackingIterStart(const vpRBFeatureTrackerInput &, const vpHomogeneousMatrix &) VP_OVERRIDE
Method called when starting a tracking iteration.
void setDisplayType(vpDisplayType type)
void onTrackingIterEnd(const vpHomogeneousMatrix &) VP_OVERRIDE
Method called after the tracking iteration has finished.
void setShouldUseMask(bool useMask)
vpDisplayType m_displayType
vpDisplayType getDisplayType() const
virtual ~vpRBDenseDepthTracker()=default
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 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 computeVVSIter(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cMo, unsigned int iteration)=0
Contains an M-estimator and various influence function.
Implementation of a rotation matrix and operations on such kind of matrices.
Class that consider the case of a translation vector.
std::array< double, 2 > pixelPos
std::array< double, 3 > oX
std::array< double, 3 > objectNormal
std::array< double, 3 > observation