Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpCombinedDepthAndColorMask.cpp
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
31#include <visp3/rbt/vpCombinedDepthAndColorMask.h>
32
33#include <visp3/rbt/vpRBFeatureTrackerInput.h>
34#include <visp3/core/vpImageFilter.h>
35
36#if defined(VISP_HAVE_NLOHMANN_JSON)
37#include VISP_NLOHMANN_JSON(json.hpp)
38#endif
39
41
43 const vpRBFeatureTrackerInput &previousFrame,
44 vpImage<float> &mask)
45{
46 m_colorMask.updateMask(frame, previousFrame, m_color);
47 m_depthMask.updateMask(frame, previousFrame, m_depth);
48
49 bool computeOnlyOnBB = m_colorMask.isComputedOnlyOnBoundingBox() && m_depthMask.isComputedOnlyOnBoundingBox();
50 if (!computeOnlyOnBB) {
51 mask.resize(m_color.getHeight(), m_color.getWidth());
52#ifdef VISP_HAVE_OPENMP
53#pragma omp parallel for
54#endif
55 for (int i = 0; i < static_cast<int>(m_color.getSize()); ++i) {
56 mask.bitmap[i] = std::min(m_color.bitmap[i], m_depth.bitmap[i]);
57 }
58 }
59 else {
60 mask.resize(m_color.getHeight(), m_color.getWidth(), 0.f);
61
62 const vpRect renderBB = frame.renders.boundingBox;
63 const int top = static_cast<int>(renderBB.getTop());
64 const int left = static_cast<int>(renderBB.getLeft());
65 const int bottom = std::min(static_cast<int>(m_color.getHeight()) - 1, static_cast<int>(renderBB.getBottom()));
66 const int right = std::min(static_cast<int>(m_color.getWidth()) - 1, static_cast<int>(renderBB.getRight()));
67#ifdef VISP_HAVE_OPENMP
68#pragma omp parallel for
69#endif
70 for (int i = top; i <= bottom; ++i) {
71 const float *const colorProbaRow = m_color[i];
72 const float *const depthProbaRow = m_depth[i];
73 float *const maskRow = mask[i];
74 for (unsigned int j = left; j <= static_cast<unsigned int>(right); ++j) {
75 maskRow[j] = std::min(colorProbaRow[j], depthProbaRow[j]);
76 }
77 }
78 }
79}
80
81#if defined(VISP_HAVE_NLOHMANN_JSON)
83{
84 m_colorMask.loadJsonConfiguration(json["color"]);
85 m_depthMask.loadJsonConfiguration(json["depth"]);
86}
87#endif
88
89END_VISP_NAMESPACE
void loadJsonConfiguration(const nlohmann::json &json) VP_OVERRIDE
void updateMask(const vpRBFeatureTrackerInput &frame, const vpRBFeatureTrackerInput &previousFrame, vpImage< float > &mask) VP_OVERRIDE
Definition of the vpImage class member functions.
Definition vpImage.h:131
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition vpImage.h:544
Type * bitmap
points toward the bitmap
Definition vpImage.h:135
All the data related to a single tracking frame. This contains both the input data (from a real camer...
vpRBRenderData renders
camera parameters
Defines a rectangle in the plane.
Definition vpRect.h:79
double getLeft() const
Definition vpRect.h:173
double getRight() const
Definition vpRect.h:179
double getBottom() const
Definition vpRect.h:97
double getTop() const
Definition vpRect.h:192