YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
RGBDSensorParamParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
8#include <yarp/os/LogStream.h>
9
10using namespace yarp::os;
11using namespace yarp::dev;
12
13namespace {
14YARP_LOG_COMPONENT(RGBDSENSORPARAMPARSER, "yarp.dev.RGBDSensorParamParser")
15}
16
17static bool checkParam(const Bottle& input, RGBDSensorParamParser::RGBDParam& param, bool& found)
18{
19 bool ret = false;
20 Bottle bt=input.findGroup(param.name).tail(); // the first element is the name of the parameter
21
22 if (!bt.isNull())
23 {
24 Bottle* b;
25 if (param.size>1 && bt.size()==1)
26 {
27 b = bt.get(0).asList();
28 }
29 else
30 {
31 b = &bt;
32 }
33 if (b->isNull())
34 {
35 yCError(RGBDSENSORPARAMPARSER) << "Check"<<param.name<<"in config file";
36 return false;
37 }
38 if (b->size() != param.size)
39 {
40 yCError(RGBDSENSORPARAMPARSER) << "Parameter" << param.name << "size should be" << param.size;
41 return false;
42 }
43 param.val.resize(param.size);
44 for (size_t i=0;i<b->size();i++)
45 {
46 ret = true;
47 param.val[i] = b->get(i);
48 found = true;
49 }
50 }
51 else
52 {
53 ret = true;
54 found = false;
55 }
56 return ret;
57}
58
59static bool checkParam(const Bottle& settings, const Bottle& description, RGBDSensorParamParser::RGBDParam &param)
60{
61 bool ret1, ret2, ret3;
62
63 ret3 = true;
64 ret1 = checkParam(settings, param, param.isSetting); // look for settings
65 ret2 = checkParam(description, param, param.isDescription);// look for HW_DESCRIPTION
66
67 if ( (param.isSetting) && (param.isDescription) )
68 {
69 yCError(RGBDSENSORPARAMPARSER) << "Setting " << param.name << " can either be a 'SETTING' or 'HW_DESCRIPTION', not both. Fix the config file. \
70 Look for documentation online.";
71 ret3 = false;
72 }
73 return (ret1 && ret2 && ret3);
74}
75
76
77static bool parseIntrinsic(const Searchable& config, const std::string& groupName, yarp::sig::IntrinsicParams &params)
78{
79
80 std::pair<std::string, double*> realparam;
81 std::vector<std::pair<std::string, double*> > realParams;
82 size_t i;
83
84 if (!config.check(groupName))
85 {
86 if (params.isOptional)
87 {
88 return true;
89 }
90 else
91 {
92 return false;
93 }
94 }
95 Bottle& intrinsic = config.findGroup(groupName);
96
97 realparam.first = "physFocalLength"; realparam.second = &params.physFocalLength; realParams.push_back(realparam);
98 realparam.first = "focalLengthX"; realparam.second = &params.focalLengthX; realParams.push_back(realparam);
99 realparam.first = "focalLengthY"; realparam.second = &params.focalLengthY; realParams.push_back(realparam);
100 realparam.first = "principalPointX"; realparam.second = &params.principalPointX; realParams.push_back(realparam);
101 realparam.first = "principalPointY"; realparam.second = &params.principalPointY; realParams.push_back(realparam);
102
103 for(i = 0; i < realParams.size(); i++)
104 {
105 if (!intrinsic.check(realParams[i].first))
106 {
107 yCError(RGBDSENSORPARAMPARSER) << "Missing" << realParams[i].first << "param in" << groupName << "group in the configuration file";
108 return false;
109 }
110
111 *(realParams[i].second) = intrinsic.find(realParams[i].first).asFloat64();
112 }
113
114 if (!intrinsic.check("distortionModel"))
115 {
116 yCError(RGBDSENSORPARAMPARSER) << "Missing distortionModel param in configuration";
117 return false;
118 }
119
120 if (!config.check(intrinsic.find("distortionModel").asString()))
121 {
122 yCError(RGBDSENSORPARAMPARSER) << "Missing" << intrinsic.find("distortionModel").asString() << "group in configuration file";
123 return false;
124 }
125
126 Bottle& distortion = config.findGroup(intrinsic.find("distortionModel").asString());
127
128 if (!distortion.check("name"))
129 {
130 yCError(RGBDSENSORPARAMPARSER) << "Missing name param in" << config.find("distortionModel").asString() << "group in configuration file";
131 return false;
132 }
133 if (distortion.find("name").asString() != "plumb_bob")
134 {
135 yCError(RGBDSENSORPARAMPARSER) << "Only plumb_bob distortion model is supported at the moment";
136 return false;
137 }
138
139 realParams.clear();
140 realparam.first = "k1"; realparam.second = &params.distortionModel.k1; realParams.push_back(realparam);
141 realparam.first = "k2"; realparam.second = &params.distortionModel.k2; realParams.push_back(realparam);
142 realparam.first = "t1"; realparam.second = &params.distortionModel.t1; realParams.push_back(realparam);
143 realparam.first = "t2"; realparam.second = &params.distortionModel.t2; realParams.push_back(realparam);
144 realparam.first = "k3"; realparam.second = &params.distortionModel.k3; realParams.push_back(realparam);
145
146 for(i = 0; i < realParams.size(); i++)
147 {
148 if (!distortion.check(realParams[i].first))
149 {
150 yCError(RGBDSENSORPARAMPARSER) << "Missing" << realParams[i].first << "param in" << intrinsic.find("distortionModel").asString() << "group in the configuration file";
151 return false;
152 }
153 *(realParams[i].second) = distortion.find(realParams[i].first).asFloat64();
154 }
155
156 return true;
157}
158
159bool RGBDSensorParamParser::parseParam(const Searchable &config, std::vector<RGBDParam*>& params)
160{
161 bool ret = true;
162
163 if (!config.check("SETTINGS"))
164 {
165 yCError(RGBDSENSORPARAMPARSER) << "Missing SETTINGS section on the configuration file";
166 return false;
167 }
168
169 Bottle& settings = config.findGroup("SETTINGS");
170
171 if (!config.check("HW_DESCRIPTION"))
172 {
173 yCError(RGBDSENSORPARAMPARSER) << "Missing HW_DESCRIPTION section on the configuration file";
174 return false;
175 }
176
177 Bottle& description = config.findGroup("HW_DESCRIPTION");
178
179
180 for (auto& v: params)
181 {
182 if (!checkParam(settings, description, *v) ) {ret = false;}
183 }
184
185 if (!ret)
186 {
187 yCError(RGBDSENSORPARAMPARSER) << "Driver input file not correct, please fix it!";
188 return false;
189 }
190
191 if (!parseIntrinsic(config, "RGB_INTRINSIC_PARAMETERS", rgbIntrinsic))
192 {
193 yCError(RGBDSENSORPARAMPARSER) << "Incomplete or missing RGB_INTRINSIC_PARAMETERS section on the configuration file";
194 return false;
195 }
196
197
198 if (!parseIntrinsic(config, "DEPTH_INTRINSIC_PARAMETERS", depthIntrinsic))
199 {
200 yCError(RGBDSENSORPARAMPARSER) << "Incomplete or missing DEPTH_INTRINSIC_PARAMETERS section on the configuration file";
201 return false;
202 }
203
204 if (!config.check("EXTRINSIC_PARAMETERS"))
205 {
207 {
208 yCError(RGBDSENSORPARAMPARSER) << "Missing EXTRINSIC_PARAMETERS section on the configuration file";
209 return false;
210 }
211 else
212 {
213 return true;
214 }
215 }
216 else
217 {
218
219 Bottle& extrinsic = config.findGroup("EXTRINSIC_PARAMETERS");
220
221 if (!extrinsic.check("transformation"))
222 {
223 yCError(RGBDSENSORPARAMPARSER) << "Missing transformation parameter under EXTRINSIC_PARAMETERS group in configuration file";
224 return false;
225 }
226
227 Bottle transformation = extrinsic.findGroup("transformation").tail();
228 Bottle* tf;
229
230 if (transformation.size()==1)
231 {
232 tf = transformation.get(0).asList();
233 }
234 else
235 {
237 }
238 if (!(tf->size() == 4*4))
239 {
240 yCError(RGBDSENSORPARAMPARSER) << "The size of the transformation matrix is wrong";
241 return false;
242 }
243
244 for(int i = 0; i < 4; i++)
245 {
246 for(int j = 0; j < 4; j++)
247 {
248 int k = i*4+j;
249 Value& v = tf->get(k);
250 if (!v.isFloat64())
251 {
252 yCError(RGBDSENSORPARAMPARSER) << "Wrong data format on transformation matrix (position" << k << ")";
253 return false;
254 }
256 }
257 }
258 }
259
260 return ret;
261}
bool ret
static bool parseIntrinsic(const Searchable &config, const std::string &groupName, yarp::sig::IntrinsicParams &params)
static bool checkParam(const Bottle &input, RGBDSensorParamParser::RGBDParam &param, bool &found)
bool parseParam(const yarp::os::Searchable &config, std::vector< RGBDParam * > &params)
parseParam, parse the params stored in a Searchable.
yarp::sig::IntrinsicParams rgbIntrinsic
yarp::sig::IntrinsicParams depthIntrinsic
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
size_type size() const
Gets the number of elements in the bottle.
Definition Bottle.cpp:251
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
Definition Bottle.cpp:293
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Definition Bottle.cpp:277
Bottle tail() const
Get all but the first element of a bottle.
Definition Bottle.cpp:361
bool isNull() const override
Checks if the object is invalid.
Definition Bottle.cpp:343
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Definition Bottle.cpp:287
A mini-server for performing network communication in the background.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
A single value (typically within a Bottle).
Definition Value.h:43
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
Definition Value.cpp:222
virtual Bottle * asList() const
Get list value.
Definition Value.cpp:240
virtual bool isFloat64() const
Checks if value is a 64-bit floating point number.
Definition Value.cpp:150
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
The IntrinsicParams struct to handle the intrinsic parameter of cameras(RGB and RGBD either).
double focalLengthY
Result of the product of the physical focal length(mm) and the size sy of the individual imager eleme...
DistortionModel distortionModel
Distortion model of the image.
double focalLengthX
Result of the product of the physical focal length(mm) and the size sx of the individual imager eleme...
double physFocalLength
Physical focal length of the lens (m)
double principalPointX
Horizontal coordinate of the principal point of the image, as a pixel offset from the left edge.
double principalPointY
Vertical coordinate of the principal point of the image, as a pixel offset from the top edge.