YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
OpenCVGrabber_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.0)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.
10
11// Generated on: Thu May 22 20:45:26 2025
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(OpenCVGrabberParamsCOMPONENT, "yarp.device.OpenCVGrabber")
20}
21
22
26
27
28std::vector<std::string> OpenCVGrabber_ParamsParser::getListOfParams() const
29{
30 std::vector<std::string> params;
31 params.push_back("movie");
32 params.push_back("loop");
33 params.push_back("camera");
34 params.push_back("framerate");
35 params.push_back("width");
36 params.push_back("height");
37 params.push_back("flip_x");
38 params.push_back("flip_y");
39 params.push_back("transpose");
40 return params;
41}
42
43
44bool OpenCVGrabber_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
45{
46 if (paramName =="movie")
47 {
48 paramValue = m_movie;
49 return true;
50 }
51 if (paramName =="loop")
52 {
53 if (m_loop==true) paramValue = "true";
54 else paramValue = "false";
55 return true;
56 }
57 if (paramName =="camera")
58 {
59 paramValue = std::to_string(m_camera);
60 return true;
61 }
62 if (paramName =="framerate")
63 {
64 paramValue = std::to_string(m_framerate);
65 return true;
66 }
67 if (paramName =="width")
68 {
69 paramValue = std::to_string(m_width);
70 return true;
71 }
72 if (paramName =="height")
73 {
74 paramValue = std::to_string(m_height);
75 return true;
76 }
77 if (paramName =="flip_x")
78 {
79 if (m_flip_x==true) paramValue = "true";
80 else paramValue = "false";
81 return true;
82 }
83 if (paramName =="flip_y")
84 {
85 if (m_flip_y==true) paramValue = "true";
86 else paramValue = "false";
87 return true;
88 }
89 if (paramName =="transpose")
90 {
91 if (m_transpose==true) paramValue = "true";
92 else paramValue = "false";
93 return true;
94 }
95
96 yError() <<"parameter '" << paramName << "' was not found";
97 return false;
98
99}
100
101
103{
104 //This is a sub-optimal solution.
105 //Ideally getConfiguration() should return all parameters but it is currently
106 //returning only user provided parameters (excluding default values)
107 //This behaviour will be fixed in the near future.
108 std::string s_cfg = m_provided_configuration;
109 return s_cfg;
110}
111
113{
114 //Check for --help option
115 if (config.check("help"))
116 {
117 yCInfo(OpenCVGrabberParamsCOMPONENT) << getDocumentationOfDeviceParams();
118 }
119
122 //Parser of parameter movie
123 {
124 if (config.check("movie"))
125 {
126 m_movie = config.find("movie").asString();
127 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'movie' using value:" << m_movie;
128 }
129 else
130 {
131 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'movie' using DEFAULT value:" << m_movie;
132 }
133 prop_check.unput("movie");
134 }
135
136 //Parser of parameter loop
137 {
138 if (config.check("loop"))
139 {
140 m_loop = config.find("loop").asBool();
141 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'loop' using value:" << m_loop;
142 }
143 else
144 {
145 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'loop' using DEFAULT value:" << m_loop;
146 }
147 prop_check.unput("loop");
148 }
149
150 //Parser of parameter camera
151 {
152 if (config.check("camera"))
153 {
154 m_camera = config.find("camera").asInt64();
155 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'camera' using value:" << m_camera;
156 }
157 else
158 {
159 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'camera' using DEFAULT value:" << m_camera;
160 }
161 prop_check.unput("camera");
162 }
163
164 //Parser of parameter framerate
165 {
166 if (config.check("framerate"))
167 {
168 m_framerate = config.find("framerate").asFloat64();
169 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'framerate' using value:" << m_framerate;
170 }
171 else
172 {
173 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'framerate' using DEFAULT value:" << m_framerate;
174 }
175 prop_check.unput("framerate");
176 }
177
178 //Parser of parameter width
179 {
180 if (config.check("width"))
181 {
182 m_width = config.find("width").asInt64();
183 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'width' using value:" << m_width;
184 }
185 else
186 {
187 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'width' using DEFAULT value:" << m_width;
188 }
189 prop_check.unput("width");
190 }
191
192 //Parser of parameter height
193 {
194 if (config.check("height"))
195 {
196 m_height = config.find("height").asInt64();
197 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'height' using value:" << m_height;
198 }
199 else
200 {
201 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'height' using DEFAULT value:" << m_height;
202 }
203 prop_check.unput("height");
204 }
205
206 //Parser of parameter flip_x
207 {
208 if (config.check("flip_x"))
209 {
210 m_flip_x = config.find("flip_x").asBool();
211 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'flip_x' using value:" << m_flip_x;
212 }
213 else
214 {
215 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'flip_x' using DEFAULT value:" << m_flip_x;
216 }
217 prop_check.unput("flip_x");
218 }
219
220 //Parser of parameter flip_y
221 {
222 if (config.check("flip_y"))
223 {
224 m_flip_y = config.find("flip_y").asBool();
225 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'flip_y' using value:" << m_flip_y;
226 }
227 else
228 {
229 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'flip_y' using DEFAULT value:" << m_flip_y;
230 }
231 prop_check.unput("flip_y");
232 }
233
234 //Parser of parameter transpose
235 {
236 if (config.check("transpose"))
237 {
238 m_transpose = config.find("transpose").asBool();
239 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'transpose' using value:" << m_transpose;
240 }
241 else
242 {
243 yCInfo(OpenCVGrabberParamsCOMPONENT) << "Parameter 'transpose' using DEFAULT value:" << m_transpose;
244 }
245 prop_check.unput("transpose");
246 }
247
248 /*
249 //This code check if the user set some parameter which are not check by the parser
250 //If the parser is set in strict mode, this will generate an error
251 if (prop_check.size() > 0)
252 {
253 bool extra_params_found = false;
254 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
255 {
256 if (m_parser_is_strict)
257 {
258 yCError(OpenCVGrabberParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
259 extra_params_found = true;
260 }
261 else
262 {
263 yCWarning(OpenCVGrabberParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
264 }
265 }
266
267 if (m_parser_is_strict && extra_params_found)
268 {
269 return false;
270 }
271 }
272 */
273 return true;
274}
275
276
278{
279 std::string doc;
280 doc = doc + std::string("\n=============================================\n");
281 doc = doc + std::string("This is the help for device: OpenCVGrabber\n");
282 doc = doc + std::string("\n");
283 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
284 doc = doc + std::string("'movie': if present, read an .avi file instead of opening a camera\n");
285 doc = doc + std::string("'loop': if true, and movie parameter is set, enable the loop playback of the file\n");
286 doc = doc + std::string("'camera': Id of the camera hardware device\n");
287 doc = doc + std::string("'framerate': Framerate. Default value obtained by the hardware\n");
288 doc = doc + std::string("'width': Width of the frame. Default value obtained by the hardware\n");
289 doc = doc + std::string("'height': Height of the frame. Default value obtained by the hardware\n");
290 doc = doc + std::string("'flip_x': Flip along the x axis\n");
291 doc = doc + std::string("'flip_y': flip along the y axis\n");
292 doc = doc + std::string("'transpose': Rotate the image by 90 degrees\n");
293 doc = doc + std::string("\n");
294 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
295 doc = doc + " yarpdev --device openCVGrabber --movie <optional_value> --loop false --camera 0 --framerate -1 --width 0 --height 0 --flip_x false --flip_y false --transpose false\n";
296 doc = doc + std::string("Using only mandatory params:\n");
297 doc = doc + " yarpdev --device openCVGrabber\n";
298 doc = doc + std::string("=============================================\n\n"); return doc;
299}
#define yError(...)
Definition Log.h:361
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::string getConfiguration() const override
Return the configuration of the device.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
A class for storing options and configuration information.
Definition Property.h:33
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
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 std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)