36#ifndef VP_RB_PROBABILISTIC_3D_DRIFT_DETECTOR_H
37#define VP_RB_PROBABILISTIC_3D_DRIFT_DETECTOR_H
39#include <visp3/core/vpCameraParameters.h>
40#include <visp3/core/vpRGBf.h>
41#include <visp3/core/vpRGBa.h>
43#include <visp3/rbt/vpRBDriftDetector.h>
49template <
typename T>
class vpImage;
138 const vpRGBf diffSqr(diff.
R * diff.
R, diff.
G * diff.
G, diff.
B * diff.
B);
167 const double proba = 1.0 - erf(std::max(std::max(abs(diff.
R), abs(diff.
G)), abs(diff.
B)) / sqrt(2));
207 return std::pow(p[0] -
X[0], 2) + std::pow(p[1] -
X[1], 2) + std::pow(p[2] -
X[2], 2);
211 std::array<double, 3> &pC, std::array<double, 2> &proj, std::array<int, 2> &px)
213 const double *T = cTo.
data;
214 pC[0] = (T[0] *
X[0] + T[1] *
X[1] + T[2] *
X[2] + T[3]);
215 pC[1] = (T[4] *
X[0] + T[5] *
X[1] + T[6] *
X[2] + T[7]);
216 pC[2] = (T[8] *
X[0] + T[9] *
X[1] + T[10] *
X[2] + T[11]);
217 proj[0] = pC[0] / pC[2];
218 proj[1] = pC[1] / pC[2];
219 px[0] =
static_cast<int>((proj[0] * cam.get_px()) + cam.get_u0());
220 px[1] =
static_cast<int>((proj[1] * cam.get_py()) + cam.get_v0());
225 stats.update(currentColor, updateRate);
230 return vpRGBa(
static_cast<unsigned int>(
stats.mean.R),
static_cast<unsigned int>(
stats.mean.G),
static_cast<unsigned int>(
stats.mean.B));
233 std::array<double, 3>
X;
243 vpRBProbabilistic3DDriftDetector() : m_colorUpdateRate(0.2), m_initialColorSigma(25.0), m_depthSigma(0.04), m_maxError3D(0.001), m_minDist3DNewPoint(0.003), m_sampleStep(4)
257 double getScore() const VP_OVERRIDE;
259 bool hasDiverged() const VP_OVERRIDE;
286 if (distance <= 0.0) {
289 m_minDist3DNewPoint = distance;
305 if (maxError <= 0.0) {
308 m_maxError3D = maxError;
322 m_depthSigma = sigma;
336 m_initialColorSigma = sigma;
358 if (updateRate < 0.0 || updateRate > 1.f) {
361 m_colorUpdateRate = updateRate;
367 if (sampleStep == 0) {
370 m_sampleStep = sampleStep;
373#if defined(VISP_HAVE_NLOHMANN_JSON)
375 void loadRepresentation(
const std::string &);
376 void saveRepresentation(
const std::string &)
const;
385 double m_colorUpdateRate;
386 double m_initialColorSigma;
389 double m_minDist3DNewPoint;
390 unsigned int m_sampleStep;
394 std::vector<vpStored3DSurfaceColorPoint> m_points;
397#ifdef VISP_HAVE_NLOHMANN_JSON
414 p.stats =
j.at(
"stats");
420 j[
"stats"] =
p.stats;
Type * data
Address of the first element of the data array.
Generic class defining intrinsic camera parameters.
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.
virtual double getScore() const =0
Get the estimated tracking reliability. A high score should mean that the tracking is reliable....
virtual void loadJsonConfiguration(const nlohmann::json &)=0
vpRBDriftDetector()=default
virtual double score(const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cTo)=0
virtual void update(const vpRBFeatureTrackerInput &previousFrame, const vpRBFeatureTrackerInput &frame, const vpHomogeneousMatrix &cTo, const vpHomogeneousMatrix &cprevTo)=0
Update the algorithm after a new tracking step.
virtual void display(const vpImage< vpRGBa > &I)=0
Displays the information used for drift detection.
void setMinDistForNew3DPoints(double distance)
void setFilteringMax3DError(double maxError)
double getMinDistForNew3DPoints() const
Get the minimum distance criterion (in meters) that is used when trying to add new points to track fo...
double getInitialColorStandardDeviation() const
Get the standard deviation that is used to initialize the color distribution when adding a new surfac...
void setDepthStandardDeviation(double sigma)
void setColorUpdateRate(double updateRate)
Set the update rate for the color distribution. It should be between 0 and 1.
void setInitialColorStandardDeviation(double sigma)
double getColorUpdateRate() const
Get the rate at which the colors of surface points are updated.
double getDepthStandardDeviation() const
Get the standard deviation that is used when computing the probability that the observed depth Z is t...
unsigned int getSampleStep() const
vpRBProbabilistic3DDriftDetector()
double getFilteringMax3DError() const
Returns the maximum 3D distance (in meters) above which a tracked surface point is rejected for the d...
void setSampleStep(unsigned int sampleStep)
Online estimation of a Gaussian color distribution , Where is a diagonal variance matrix .
void init(const vpRGBf &c, const vpRGBf &var)
double probability(const vpRGBf &c)
Computes the probability that the input color was sampled from the estimated distribution.
ColorStatistics()=default
double covarianceScaleFactor() const
void update(const vpRGBf &c, float weight)
Update the color distribution with a new sample c.
std::array< double, 3 > renderX
std::array< int, 2 > projCurrPx
std::array< double, 2 > projCurr
Point position in the current and previous camera frames.
std::array< double, 3 > X
void fastProjection(const vpHomogeneousMatrix &cTo, const vpCameraParameters &cam, std::array< double, 3 > &pC, std::array< double, 2 > &proj, std::array< int, 2 > &px)
void update(const vpHomogeneousMatrix &cTo, const vpHomogeneousMatrix &renderTo, const vpCameraParameters &cam)
vpRGBa getDisplayColor() const
std::array< double, 3 > currX
Color statistics associated to this point.
void updateColor(const vpRGBf ¤tColor, float updateRate)
std::array< double, 2 > projRender
std::array< int, 2 > projRenderPx
double squaredDist(const std::array< double, 3 > &p) const