31 #include <visp3/rbt/vpColorHistogramMask.h>
33 #include <visp3/rbt/vpRBFeatureTracker.h>
35 #if defined(VISP_HAVE_NLOHMANN_JSON)
36 #include VISP_NLOHMANN_JSON(json.hpp)
51 const int height =
static_cast<int>(rgb.
getHeight()), width =
static_cast<int>(rgb.
getWidth());
52 m_mask.
resize(height, width,
false);
54 const int top =
static_cast<int>(renderBB.
getTop());
55 const int left =
static_cast<int>(renderBB.
getLeft());
56 const int bottom = std::min(height - 1,
static_cast<int>(renderBB.
getBottom()));
57 const int right = std::min(width - 1,
static_cast<int>(renderBB.
getRight()));
61 if (depth.
getSize() > 0 && m_depthErrorTolerance > 0.f) {
62 for (
unsigned int i = top; i <= static_cast<unsigned int>(bottom); ++i) {
63 for (
unsigned int j = left; j <= static_cast<unsigned int>(right); ++j) {
64 m_mask[i][j] = renderDepth[i][j] > 0.f && fabs(renderDepth[i][j] - depth[i][j]) <= m_depthErrorTolerance;
69 for (
unsigned int i = top; i <= static_cast<unsigned int>(bottom); ++i) {
70 for (
unsigned int j = left; j <= static_cast<unsigned int>(right); ++j) {
71 m_mask[i][j] = renderDepth[i][j] > 0.f;
77 const float pObject =
static_cast<float>(m_histObjectFrame.
getNumPixels()) /
static_cast<float>(m_mask.
getSize());
78 const float pBackground = 1.f - pObject;
82 m_histObject.
merge(m_histObjectFrame, m_objectUpdateRate);
84 if (m_computeOnBBOnly) {
92 if (pBackground != 0.f) {
93 m_histBackground.
merge(m_histBackgroundFrame, m_backgroundUpdateRate);
95 if (m_computeOnBBOnly) {
104 if (m_computeOnBBOnly) {
105 mask.
resize(height, width, 0.f);
106 #pragma omp parallel for
107 for (
unsigned int i = top; i <= static_cast<unsigned int>(bottom); ++i) {
108 for (
unsigned int j = left; j <= static_cast<unsigned int>(right); ++j) {
109 const float poPix = m_probaObject[i][j];
110 const float pbPix = m_probaBackground[i][j];
112 float denom = (pObject * poPix + pBackground * pbPix);
113 mask[i][j] = (denom > 0.f) * std::max(0.f, std::min(1.f, (poPix / denom)));
114 m_mask[i][j] = renderDepth[i][j] > 0.f && fabs(renderDepth[i][j] - depth[i][j]) <= m_depthErrorTolerance;
119 mask.
resize(height, width);
120 for (
unsigned int i = 0; i < mask.
getSize(); ++i) {
123 const float poPix = m_probaObject.
bitmap[i];
124 const float pbPix = m_probaBackground.
bitmap[i];
126 float denom = (pObject * poPix + pBackground * pbPix);
127 mask.
bitmap[i] = (denom > 0.f) * std::max(0.f, std::min(1.f, (poPix / denom)));
134 #if defined(VISP_HAVE_NLOHMANN_JSON)
138 m_backgroundUpdateRate = json.at(
"backgroundUpdateRate");
139 m_objectUpdateRate = json.at(
"objectUpdateRate");
140 m_depthErrorTolerance = json.at(
"maxDepthError");
141 m_computeOnBBOnly = json.value(
"computeOnlyOnBoundingBox", m_computeOnBBOnly);
void loadJsonConfiguration(const nlohmann::json &json) VP_OVERRIDE
void setBinNumber(unsigned int N)
void updateMask(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, vpImage< float > &mask) VP_OVERRIDE
unsigned int getNumPixels() const
static void computeSplitHistograms(const vpImage< vpRGBa > &image, const vpImage< bool > &mask, vpColorHistogram &inMask, vpColorHistogram &outsideMask)
void computeProbas(const vpImage< vpRGBa > &image, vpImage< float > &proba) const
void merge(const vpColorHistogram &other, float alpha)
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
unsigned int getSize() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
Defines a rectangle in the plane.
vpImage< float > depth
Image containing the per-pixel normal vector (RGB, in object space)