Argus Camera Sample Argus Camera Sample

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AppModuleGeneric.cpp
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2016-2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of NVIDIA CORPORATION nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "AppModuleGeneric.h"
33 #include "XMLConfig.h"
34 #include "Dispatcher.h"
35 #include "Error.h"
36 #include "Options.h"
37 #include "Window.h"
38
39 #include <Argus/Ext/DeFog.h>
40
41 namespace ArgusSamples
42 {
43
44 /**
45 * Default configuration file name
46 */
47 #define DEFAULT_CONFIG_FILE "argusAppConfig.xml"
48
49 /* static */ bool AppModuleGeneric::info(void *userPtr, const char *optArg)
50 {
51 std::string info;
52 PROPAGATE_ERROR(Dispatcher::getInstance().getInfo(info));
53 printf("%s\n", info.c_str());
54
55 return true;
56 }
57
58 /* static */ bool AppModuleGeneric::loadConfig(void *userPtr, const char *optArg)
59 {
60 /// @todo ask for file if called from GUI
61
62 const char *configFile = DEFAULT_CONFIG_FILE;
63 if (optArg)
64 configFile = optArg;
65 PROPAGATE_ERROR(ArgusSamples::loadConfig(configFile));
66 return true;
67 }
68
69 /* static */ bool AppModuleGeneric::saveConfig(void *userPtr, const char *optArg)
70 {
71 /// @todo ask for file if called from GUI
72
73 const char *configFile = DEFAULT_CONFIG_FILE;
74 if (optArg)
75 configFile = optArg;
76 PROPAGATE_ERROR(ArgusSamples::saveConfig(configFile));
77 return true;
78 }
79
80 /* static */ bool AppModuleGeneric::quit(void *userPtr, const char *optArg)
81 {
82 PROPAGATE_ERROR(Window::getInstance().requestExit());
83 return true;
84 }
85
86 AppModuleGeneric::AppModuleGeneric()
87 : m_initialized(false)
88 , m_running(false)
89 , m_guiMenuBar(NULL)
90 , m_guiContainerConfig(NULL)
91 , m_guiConfig(NULL)
92 {
93 }
94
95 AppModuleGeneric::~AppModuleGeneric()
96 {
97 shutdown();
98 }
99
100 bool AppModuleGeneric::initialize(Options &options)
101 {
102 if (m_initialized)
103 return true;
104
105 PROPAGATE_ERROR(options.addDescription(
106 "The supported value range of some settings is device or sensor mode dependent.\n"
107 "Use the '--info' option to get a list of the supported values.\n"));
108
109 PROPAGATE_ERROR(options.addOption(
110 Options::Option("info", 'i', "",
111 Options::Option::TYPE_ACTION,"print information on devices.", info)));
112
113 PROPAGATE_ERROR(options.addOption(
114 Options::Option("loadconfig", 0, "FILE",
115 Options::Option::TYPE_ACTION, "load configuration from XML FILE. ",
116 loadConfig, this, DEFAULT_CONFIG_FILE)));
117 PROPAGATE_ERROR(options.addOption(
118 Options::Option("saveconfig", 0, "FILE",
119 Options::Option::TYPE_ACTION, "save configuration to XML FILE. ",
120 saveConfig, this, DEFAULT_CONFIG_FILE)));
121
122 PROPAGATE_ERROR(options.addOption(
123 createValueOption("verbose", 0, "0 or 1", "enable verbose mode.",
124 Dispatcher::getInstance().m_verbose, "1")));
125 PROPAGATE_ERROR(options.addOption(
126 createValueOption("kpi", 0, "0 or 1", "enable kpi mode.",
127 Dispatcher::getInstance().m_kpi, "1")));
128 PROPAGATE_ERROR(options.addOption(
129 createValueOption("device", 'd', "INDEX", "select camera device with INDEX.",
130 Dispatcher::getInstance().m_deviceIndex)));
131
132 // source settings
133 PROPAGATE_ERROR(options.addOption(
134 createValueOption("exposuretimerange", 0, "RANGE",
135 "sets the exposure time range to RANGE, in nanoseconds.",
136 Dispatcher::getInstance().m_exposureTimeRange)));
137 PROPAGATE_ERROR(options.addOption(
138 createValueOption("gainrange", 0, "RANGE", "sets the gain range to RANGE.",
139 Dispatcher::getInstance().m_gainRange)));
140 PROPAGATE_ERROR(options.addOption(
141 createValueOption("sensormode", 0, "INDEX", "set sensor mode to INDEX.",
142 Dispatcher::getInstance().m_sensorModeIndex)));
143 PROPAGATE_ERROR(options.addOption(
144 createValueOption("framerate", 0, "RATE",
145 "set the sensor frame rate to RATE. If RATE is 0 then VFR (variable frame rate) is "
146 "enabled.", Dispatcher::getInstance().m_frameRate)));
147 PROPAGATE_ERROR(options.addOption(
148 createValueOption("focusposition", 0, "POSITION",
149 "sets the focus position to POSITION, in focuser units.",
150 Dispatcher::getInstance().m_focusPosition)));
151 PROPAGATE_ERROR(options.addOption(
152 createValueOption("captureyuvformat", 0, "FORMAT",
153 "YUV format for image capture.", Dispatcher::getInstance().m_captureYuvFormat)));
154
155 // output settings
156 PROPAGATE_ERROR(options.addOption(
157 createValueOption("outputsize", 0, "WIDTHxHEIGHT",
158 "set the still and video output size to WIDTHxHEIGHT (e.g. 1920x1080). If WIDTHxHEIGHT "
159 "is '0x0' the output size is the sensor mode size.",
160 Dispatcher::getInstance().m_outputSize)));
161 PROPAGATE_ERROR(options.addOption(
162 createValueOption("outputpath", 0, "PATH",
163 "set the output file path. A file name, an incrementing index and the file extension"
164 " will be appended. E.g. setting 'folder/' will result in 'folder/image0.jpg' or "
165 "'folder/video0.mp4'. '/dev/null' can be used to discard output.",
166 Dispatcher::getInstance().m_outputPath)));
167
168 // stream settings
169 PROPAGATE_ERROR(options.addOption(
170 createValueOption("denoise", 0, "MODE", "set the denoising mode.",
171 Dispatcher::getInstance().m_denoiseMode)));
172 PROPAGATE_ERROR(options.addOption(
173 createValueOption("denoisestrength", 0, "POSITION", "set the denoising strength.",
174 Dispatcher::getInstance().m_denoiseStrength)));
175 PROPAGATE_ERROR(options.addOption(
176 createValueOption("edgeenhance", 0, "MODE", "set the edge enhancement mode.",
177 Dispatcher::getInstance().m_edgeEnhanceMode)));
178 PROPAGATE_ERROR(options.addOption(
179 createValueOption("edgeenhancestrength", 0, "POSITION",
180 "set the edge enhancement strength.",
181 Dispatcher::getInstance().m_edgeEnhanceStrength)));
182
183 // auto control settings
184 PROPAGATE_ERROR(options.addOption(
185 createValueOption("aeantibanding", 0, "MODE", "set the auto exposure antibanding mode.",
186 Dispatcher::getInstance().m_aeAntibandingMode)));
187 PROPAGATE_ERROR(options.addOption(
188 createValueOption("aelock", 0, "LOCK", "set the auto exposure lock.",
189 Dispatcher::getInstance().m_aeLock)));
190 PROPAGATE_ERROR(options.addOption(
191 createValueOption("awblock", 0, "LOCK", "set the auto white balance lock.",
192 Dispatcher::getInstance().m_awbLock)));
193 PROPAGATE_ERROR(options.addOption(
194 createValueOption("awb", 0, "MODE", "set the auto white balance mode.",
195 Dispatcher::getInstance().m_awbMode)));
196 PROPAGATE_ERROR(options.addOption(
197 createValueOption("exposurecompensation", 0, "COMPENSATION",
198 "set the exposure compensation to COMPENSATION.",
199 Dispatcher::getInstance().m_exposureCompensation)));
200 PROPAGATE_ERROR(options.addOption(
201 createValueOption("ispdigitalgainrange", 0, "RANGE",
202 "sets the ISP digital gain range.",
203 Dispatcher::getInstance().m_ispDigitalGainRange)));
204
205 if (Dispatcher::getInstance().supportsExtension(Argus::EXT_DE_FOG))
206 {
207 // DeFog extension settings
208 PROPAGATE_ERROR(options.addOption(
209 createValueOption("defog", 0, "ENABLE",
210 "set the DeFog enable flag to ENABLE.",
211 Dispatcher::getInstance().m_deFogEnable)));
212 PROPAGATE_ERROR(options.addOption(
213 createValueOption("defogamount", 0, "AMOUNT",
214 "sets the amount of fog to be removed to AMOUNT.",
215 Dispatcher::getInstance().m_deFogAmount)));
216 PROPAGATE_ERROR(options.addOption(
217 createValueOption("defogquality", 0, "QUALITY",
218 "sets the quality of the DeFog effect to QUALITY.",
219 Dispatcher::getInstance().m_deFogQuality)));
220 }
221
222 m_initialized = true;
223
224 return true;
225 }
226
227 bool AppModuleGeneric::shutdown()
228 {
229 if (!m_initialized)
230 return true;
231
232 PROPAGATE_ERROR_CONTINUE(stop());
233
234 delete m_guiConfig;
235 m_guiConfig = NULL;
236
237 m_initialized = false;
238
239 return true;
240 }
241
242 bool AppModuleGeneric::start(Window::IGuiMenuBar *iGuiMenuBar,
243 Window::IGuiContainer *iGuiContainerConfig)
244 {
245 if (m_running)
246 return true;
247
248 if (iGuiMenuBar && !m_guiMenuBar)
249 {
250 // initialize the menu
251
252 UniquePointer<Window::IGuiMenu> menu;
253 UniquePointer<Window::IGuiMenuItem> item;
254
255 // create the elements
256 Window::IGuiMenu *fileMenu = iGuiMenuBar->getMenu("File");
257 if (!fileMenu)
258 {
259 PROPAGATE_ERROR(Window::IGuiMenu::create("File", &menu));
260 PROPAGATE_ERROR(iGuiMenuBar->add(menu.get()));
261 fileMenu = menu.get();
262 menu.release();
263 }
264 PROPAGATE_ERROR(Window::IGuiMenuItem::create("Load config", AppModuleGeneric::loadConfig,
265 NULL, &item));
266 PROPAGATE_ERROR(fileMenu->add(item.get()));
267 item.release();
268 PROPAGATE_ERROR(Window::IGuiMenuItem::create("Save Config", AppModuleGeneric::saveConfig,
269 NULL, &item));
270 PROPAGATE_ERROR(fileMenu->add(item.get()));
271 item.release();
272 PROPAGATE_ERROR(Window::IGuiMenuItem::create("Quit", AppModuleGeneric::quit, NULL,
273 &item));
274 PROPAGATE_ERROR(fileMenu->add(item.get()));
275 item.release();
276
277 Window::IGuiMenu *helpMenu = iGuiMenuBar->getMenu("Help");
278 if (!helpMenu)
279 {
280 PROPAGATE_ERROR(Window::IGuiMenu::create("Help", &menu));
281 PROPAGATE_ERROR(iGuiMenuBar->add(menu.get()));
282 helpMenu = menu.get();
283 menu.release();
284 }
285 PROPAGATE_ERROR(Window::IGuiMenuItem::create("Info", AppModuleGeneric::info, NULL,
286 &item));
287 PROPAGATE_ERROR(helpMenu->add(item.get()));
288 item.release();
289
290 m_guiMenuBar = iGuiMenuBar;
291 }
292
293 if (iGuiContainerConfig && !m_guiContainerConfig)
294 {
295 // initialize the GUI
296
297 // create a grid container
298 PROPAGATE_ERROR(Window::IGuiContainerGrid::create(&m_guiConfig));
299
300 // create the elements
301 UniquePointer<Window::IGuiElement> element;
302 Dispatcher &dispatcher = Dispatcher::getInstance();
303
304 Window::IGuiContainerGrid::BuildHelper buildHelper(m_guiConfig);
305
306 #define CREATE_GUI_ELEMENT(_NAME, _VALUE) \
307 PROPAGATE_ERROR(Window::IGuiElement::createValue(&dispatcher._VALUE, &element));\
308 PROPAGATE_ERROR(buildHelper.append(_NAME, element.get())); \
309 element.release();
310
311 #define CREATE_GUI_ELEMENT_COMBO_BOX(_NAME, _VALUE, _FROMTYPE, _TOTYPE) \
312 assert(sizeof(_FROMTYPE) == sizeof(_TOTYPE)); \
313 PROPAGATE_ERROR(Window::IGuiElement::createValue(reinterpret_cast< \
314 Value<_TOTYPE>*>(&dispatcher._VALUE), &element)); \
315 PROPAGATE_ERROR(buildHelper.append(_NAME, element.get())); \
316 element.release();
317
318 #define CREATE_GUI_ELEMENT_PATH_CHOOSER(_NAME, _VALUE) \
319 PROPAGATE_ERROR(Window::IGuiElement::createFileChooser(&dispatcher._VALUE, \
320 true, &element)); \
321 PROPAGATE_ERROR(buildHelper.append(_NAME, element.get())); \
322 element.release();
323
324 CREATE_GUI_ELEMENT("Verbose", m_verbose);
325 CREATE_GUI_ELEMENT("KPI", m_kpi);
326 CREATE_GUI_ELEMENT("Device", m_deviceIndex);
327
328 CREATE_GUI_ELEMENT("Exposure time range (ns)", m_exposureTimeRange);
329 CREATE_GUI_ELEMENT("Gain range", m_gainRange);
330 CREATE_GUI_ELEMENT("ISP digital gain range", m_ispDigitalGainRange);
331
332 CREATE_GUI_ELEMENT_COMBO_BOX("Sensor mode index", m_sensorModeIndex,
333 uint32_t, Window::IGuiElement::ValueTypeEnum);
334 CREATE_GUI_ELEMENT_COMBO_BOX("YUV format", m_captureYuvFormat,
335 Argus::PixelFormat, Argus::NamedUUID);
336 CREATE_GUI_ELEMENT("Frame rate", m_frameRate);
337 CREATE_GUI_ELEMENT("Focus position", m_focusPosition);
338 CREATE_GUI_ELEMENT("Output size", m_outputSize);
339
340 CREATE_GUI_ELEMENT_PATH_CHOOSER("Output path", m_outputPath);
341
342 CREATE_GUI_ELEMENT_COMBO_BOX("De-Noise mode", m_denoiseMode,
343 Argus::DenoiseMode, Argus::NamedUUID);
344 CREATE_GUI_ELEMENT("De-Noise strength", m_denoiseStrength);
345 CREATE_GUI_ELEMENT_COMBO_BOX("Edge Enhance mode", m_edgeEnhanceMode,
346 Argus::EdgeEnhanceMode, Argus::NamedUUID);
347 CREATE_GUI_ELEMENT("Edge Enhance strength", m_edgeEnhanceStrength);
348
349 CREATE_GUI_ELEMENT_COMBO_BOX("AE antibanding mode", m_aeAntibandingMode,
350 Argus::AeAntibandingMode, Argus::NamedUUID);
351
352 CREATE_GUI_ELEMENT("AE Lock", m_aeLock);
353 CREATE_GUI_ELEMENT("AWB Lock", m_awbLock);
354 CREATE_GUI_ELEMENT_COMBO_BOX("AWB mode", m_awbMode,
355 Argus::AwbMode, Argus::NamedUUID);
356 CREATE_GUI_ELEMENT("Exposure compensation (ev)", m_exposureCompensation);
357
358 #undef CREATE_GUI_ELEMENT
359 #undef CREATE_GUI_ELEMENT_COMBO_BOX
360 #undef CREATE_GUI_ELEMENT_PATH_CHOOSER
361
362 m_guiContainerConfig = iGuiContainerConfig;
363 }
364
365 if (m_guiContainerConfig)
366 PROPAGATE_ERROR(m_guiContainerConfig->add(m_guiConfig));
367
368 m_running = true;
369
370 return true;
371 }
372
373 bool AppModuleGeneric::stop()
374 {
375 if (!m_running)
376 return true;
377
378 if (m_guiContainerConfig)
379 PROPAGATE_ERROR(m_guiContainerConfig->remove(m_guiConfig));
380
381 m_running = true;
382
383 return true;
384 }
385
386 }; // namespace ArgusSamples