Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpRBSilhouettePointsExtractionSettings.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 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
35
36#ifndef VP_RB_SILHOUETTE_POINTS_EXTRACTION_SETTINGS_H
37#define VP_RB_SILHOUETTE_POINTS_EXTRACTION_SETTINGS_H
38
39#include <visp3/core/vpConfig.h>
40
41#if defined(VISP_HAVE_PANDA3D)
42#include <visp3/core/vpMath.h>
43#include <visp3/core/vpMatrix.h>
44#include <visp3/core/vpImage.h>
45#include <visp3/core/vpUniRand.h>
46
47
48#if defined(VISP_HAVE_NLOHMANN_JSON)
49#include VISP_NLOHMANN_JSON(json.hpp)
50#endif
51
52
54
68{
69
70private:
71 unsigned int m_sampleStep;
72 int m_maxNumPoints;
73 unsigned int m_border;
74
75 double m_depthThreshold;
76 bool m_thresholdIsRelative;
77 bool m_preferPreviousPoints;
78
79 void sampleWithoutReplacement(size_t count, size_t vectorSize, std::vector<size_t> &indices, vpUniRand &random) const
80 {
81 count = std::min(count, vectorSize);
82 indices.resize(count);
83 size_t added = 0;
84 for (size_t i = 0; i < vectorSize; ++i) {
85 const double randomVal = random.uniform(0.0, 1.0);
86 if ((vectorSize - i) * randomVal < (count - added)) {
87 indices[added++] = i;
88 }
89 if (added == count) {
90 break;
91 }
92 }
93 }
94
95public:
96
101
102 double getThreshold() const { return m_depthThreshold; }
103 void setThreshold(double lambda) { m_depthThreshold = lambda; }
104 bool thresholdIsRelative() const { return m_thresholdIsRelative; }
105 void setThresholdIsRelative(bool isRelative) { m_thresholdIsRelative = isRelative; }
106 bool preferPreviousPoints() const { return m_preferPreviousPoints; }
107 void setPreferPreviousPoints(bool prefer) { m_preferPreviousPoints = prefer; }
108
109
110 int getMaxCandidates() const { return m_maxNumPoints; }
111 void setMaxCandidates(int maxCandidates) { m_maxNumPoints = maxCandidates; }
112 unsigned int getSampleStep() const { return m_sampleStep; }
113 void setSampleStep(unsigned int a)
114 {
115 if (m_sampleStep == 0) {
116 throw vpException(vpException::badValue, "Sample step should be greater than 0");
117 }
118 m_sampleStep = a;
119 }
120
121 std::vector<std::pair<unsigned int, unsigned int>> getSilhouetteCandidates(
122 const vpImage<unsigned char> &validSilhouette, const vpImage<float> &renderDepth,
123 const vpCameraParameters &cam, const vpHomogeneousMatrix &cTcp,
124 const std::vector<vpRBSilhouettePoint> &previousPoints, long randomSeed = 41) const;
125
126#if defined(VISP_HAVE_NLOHMANN_JSON)
127 inline friend void from_json(const nlohmann::json &j, vpSilhouettePointsExtractionSettings &settings);
128#endif
129
130};
131
132#if defined(VISP_HAVE_NLOHMANN_JSON)
133inline void from_json(const nlohmann::json &j, vpSilhouettePointsExtractionSettings &settings)
134{
135 nlohmann::json thresholdSettings = j.at("threshold");
136 std::string thresholdType = thresholdSettings.at("type");
137 settings.m_thresholdIsRelative = thresholdType == "relative";
138 settings.m_depthThreshold = thresholdSettings.at("value");
139
140 nlohmann::json samplingSettings = j.at("sampling");
141 settings.m_preferPreviousPoints = samplingSettings.at("reusePreviousPoints");
142 settings.m_maxNumPoints = samplingSettings.at("numPoints");
143 settings.setSampleStep(samplingSettings.at("samplingRate"));
144}
145#endif
146
147END_VISP_NAMESPACE
148
149#endif
150#endif
Generic class defining intrinsic camera parameters.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ badValue
Used to indicate that a value is not in the allowed range.
Definition vpException.h:73
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Silhouette point simple candidate representation.
const vpSilhouettePointsExtractionSettings & operator=(const vpSilhouettePointsExtractionSettings &rend)
friend void from_json(const nlohmann::json &j, vpSilhouettePointsExtractionSettings &settings)
Class for generating random numbers with uniform probability density.
Definition vpUniRand.h:127
int uniform(int a, int b)