31#include <visp3/rbt/vpRBVisualOdometryUtils.h>
32#include <visp3/core/vpImageFilter.h>
34#include <visp3/core/vpMatrix.h>
35#include <visp3/rbt/vpRBFeatureTrackerInput.h>
39#include <visp3/core/vpRobust.h>
40#include <visp3/core/vpExponentialMap.h>
41#include <visp3/core/vpHomogeneousMatrix.h>
45std::pair<std::vector<unsigned int>, std::vector<unsigned int>>
48 double minMaskConfidence,
double minEdgeDistObject,
49 double minEdgeDistEnv)
51 std::vector<unsigned int> objIndices, envIndices;
54 const bool useMask = frame.
hasMask() && minMaskConfidence > 0.0;
57 std::vector<std::pair<double, double>> actualSilhouettePoints;
61 actualSilhouettePoints.push_back(std::make_pair(
62 static_cast<double>(p.i),
static_cast<double>(p.j)
67 const auto testDistanceEdge = [&actualSilhouettePoints](
double u,
double v,
double threshold) ->
bool {
68 for (
const std::pair<double, double> &p: actualSilhouettePoints) {
70 if (dist2 < threshold) {
77 for (
unsigned int i = 0; i < keypoints.
getRows(); ++i) {
78 double u = keypoints[i][0], v = keypoints[i][1];
79 if (u < 2.0 || v < 2.0 || u >= w - 2 || v >= h - 2) {
82 const unsigned int ui =
static_cast<unsigned int>(u), vi =
static_cast<unsigned int>(v);
83 const double Z =
static_cast<double>(renderDepth[vi][ui]);
86 double maskValue = 1.f;
89 for (
int ki = -1; ki <= 1; ++ki) {
90 for (
int kj = -1; kj <= 1; ++kj) {
91 maskValue += frame.
mask[vi + ki][ui + kj];
96 if (!useMask || maskValue >= minMaskConfidence) {
97 bool notTooCloseToEdge = thresholdObject <= 0 || testDistanceEdge(u, v, thresholdObject);
98 if (notTooCloseToEdge) {
99 objIndices.push_back(i);
104 bool notTooCloseToEdge = thresholdEnv <= 0 || testDistanceEdge(u, v, thresholdEnv);
105 if (notTooCloseToEdge) {
106 envIndices.push_back(i);
110 return std::make_pair(objIndices, envIndices);
126 vpMatrix points3dTranspose = points3d.
t();
132 double mu = parameters.
muInit;
133 double errorNormPrev = std::numeric_limits<double>::max();
134 for (
unsigned int iter = 0; iter < parameters.
maxNumIters; ++iter) {
139#ifdef VISP_HAVE_OPENMP
140#pragma omp parallel for
142 for (
int i = 0; i < static_cast<int>(points3d.
getRows()); ++i) {
143 const double X = cXt[0][i] + t[0], Y = cXt[1][i] + t[1], Z = cXt[2][i] + t[2];
144 const double x = X / Z, y = Y / Z;
145 e[i * 2] = x - observations[i][0];
146 e[i * 2 + 1] = y - observations[i][1];
148 L[i * 2][0] = -1.0 / Z; L[i * 2][1] = 0.0; L[i * 2][2] = x / Z;
149 L[i * 2][3] = x * y; L[i * 2][4] = -(1.0 + x * x); L[i * 2][5] = y;
151 L[i * 2 + 1][0] = 0.0; L[i * 2 + 1][1] = -1.0 / Z; L[i * 2 + 1][2] = y / Z;
152 L[i * 2 + 1][3] = 1.0 + y * y; L[i * 2 + 1][4] = -(x * y); L[i * 2 + 1][5] = -x;
156 for (
unsigned int i = 0; i < e.getRows(); ++i) {
157 weighted_error[i] = e[i] * weights[i];
158 for (
unsigned int j = 0; j < 6; ++j) {
159 L[i][j] *= weights[i];
166 vpColVector v = -parameters.
gain * ((H + Id * mu).pseudoInverse() * Lte);
168 double errorNormCurr = weighted_error.frobeniusNorm();
169 double improvementFactor = errorNormCurr / errorNormPrev;
181 errorNormPrev = errorNormCurr;
199 vpMatrix points3dTranspose = points3d.
t();
205 double mu = parameters.
muInit;
206 double errorNormPrev = std::numeric_limits<double>::max();
207 for (
unsigned int iter = 0; iter < parameters.
maxNumIters; ++iter) {
212#ifdef VISP_HAVE_OPENMP
213#pragma omp parallel for
215 for (
int i = 0; i < static_cast<int>(points3d.
getRows()); ++i) {
216 const double X = cXt[0][i] + t[0], Y = cXt[1][i] + t[1], Z = cXt[2][i] + t[2];
218 e[i * 3] = X - observations[i][0];
219 e[i * 3 + 1] = Y - observations[i][1];
220 e[i * 3 + 2] = Z - observations[i][2];
223 L[i * 3 + 1][1] = -1;
224 L[i * 3 + 2][2] = -1;
230 L[i * 3 + 1][5] = -X;
232 L[i * 3 + 2][3] = -Y;
237 for (
unsigned int i = 0; i < e.getRows(); ++i) {
238 weighted_error[i] = e[i] * weights[i];
239 for (
unsigned int j = 0; j < 6; ++j) {
240 L[i][j] *= weights[i];
247 vpColVector v = -parameters.
gain * ((H + Id * mu).pseudoInverse() * Lte);
249 double errorNormCurr = weighted_error.frobeniusNorm();
250 double improvementFactor = errorNormCurr / errorNormPrev;
262 errorNormPrev = errorNormCurr;
unsigned int getCols() const
unsigned int getRows() const
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ dimensionError
Bad dimension.
static vpHomogeneousMatrix direct(const vpColVector &v)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Definition of the vpImage class member functions.
unsigned int getWidth() const
unsigned int getHeight() const
static double sqr(double x)
Implementation of a matrix and operations on matrices.
static void mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C)
Silhouette point simple candidate representation.
static void levenbergMarquardtKeypoints2D(const vpMatrix &points3d, const vpMatrix &observations, const vpLevenbergMarquardtParameters ¶meters, vpHomogeneousMatrix &cTw)
static std::pair< std::vector< unsigned int >, std::vector< unsigned int > > computeIndicesObjectAndEnvironment(const vpMatrix &keypoints, const vpRBFeatureTrackerInput &frame, double minMaskConfidence, double minEdgeDistObject, double minEdgeDistEnv)
Compute the indices of the keypoints that belong to either the object (the renderered depth is greate...
static void levenbergMarquardtKeypoints3D(const vpMatrix &points3d, const vpMatrix &observations, const vpLevenbergMarquardtParameters ¶meters, vpHomogeneousMatrix &cTw)
Contains an M-estimator and various influence function.
@ TUKEY
Tukey influence function.
void MEstimator(const vpRobustEstimatorType method, const vpColVector &residues, vpColVector &weights)
Implementation of a rotation matrix and operations on such kind of matrices.
Class that consider the case of a translation vector.
double minImprovementFactor
vpImage< float > depth
Image containing the per-pixel normal vector (RGB, in object space).