Skip to content

Commit d700d09

Browse files
committed
DataRecorder tool: interface changed to use config file (#661)
1 parent 3104dff commit d700d09

File tree

3 files changed

+66
-202
lines changed

3 files changed

+66
-202
lines changed

guilib/include/rtabmap/gui/PreferencesDialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class RTABMAPGUI_EXP PreferencesDialog : public QDialog
120120

121121
virtual QString getIniFilePath() const;
122122
virtual QString getTmpIniFilePath() const;
123-
void init();
123+
void init(const QString & iniFilePath = "");
124124
void setCurrentPanelToSource();
125125
virtual QString getDefaultWorkingDirectory() const;
126126

guilib/src/PreferencesDialog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ PreferencesDialog::~PreferencesDialog() {
14281428
delete _ui;
14291429
}
14301430

1431-
void PreferencesDialog::init()
1431+
void PreferencesDialog::init(const QString & iniFilePath)
14321432
{
14331433
UDEBUG("");
14341434
//First set all default values
@@ -1438,7 +1438,7 @@ void PreferencesDialog::init()
14381438
this->setParameter(iter->first, iter->second);
14391439
}
14401440

1441-
this->readSettings();
1441+
this->readSettings(iniFilePath);
14421442
this->writeSettings(getTmpIniFilePath());
14431443

14441444
_initialized = true;

tools/DataRecorder/main.cpp

Lines changed: 63 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
#include <rtabmap/core/CameraRGBD.h>
3333
#include <rtabmap/core/CameraStereo.h>
3434
#include <rtabmap/core/Camera.h>
35+
#include <rtabmap/core/DBReader.h>
3536
#include <rtabmap/core/CameraThread.h>
3637
#include <rtabmap/gui/DataRecorder.h>
38+
#include <rtabmap/gui/PreferencesDialog.h>
3739
#include <QApplication>
3840
#include <signal.h>
3941

@@ -42,27 +44,14 @@ using namespace rtabmap;
4244
void showUsage()
4345
{
4446
printf("\nUsage:\n"
45-
"dataRecorder [options] output.db\n"
47+
"dataRecorder [options] config.ini output.db\n"
48+
"Description:\n"
49+
" A config file contains all camera parameters and driver used. That\n"
50+
" file can be generated by RTAB-Map->Preferences->Save Settings(*.ini)\n"
51+
" after modifying Source settings.\n"
4652
"Options:\n"
47-
" -hide Don't display the current cloud recorded.\n"
48-
" -debug Set debug level for the logger.\n"
49-
" -rate #.# Input rate Hz (default 0=inf)\n"
50-
" -driver Driver number to use:\n"
51-
" 0=OpenNI-PCL (Kinect)\n"
52-
" 1=OpenNI2 (Kinect and Xtion PRO Live)\n"
53-
" 2=Freenect (Kinect)\n"
54-
" 3=OpenNI-CV (Kinect)\n"
55-
" 4=OpenNI-CV-ASUS (Xtion PRO Live)\n"
56-
" 5=Freenect2 (Kinect v2)\n"
57-
" 6=DC1394 (Bumblebee2)\n"
58-
" 7=FlyCapture2 (Bumblebee2)\n"
59-
" 8=ZED stereo\n"
60-
" 9=RealSense\n"
61-
" 10=Kinect for Windows 2 SDK\n"
62-
" 11=RealSense2\n"
63-
" 12=Kinect for Azure SDK\n"
64-
" 13=MYNT EYE S\n"
65-
" -device "" Device ID (default \"\")\n");
53+
" -debug Show debug log.\n"
54+
" -hide Don't display the current cloud recorded.\n");
6655
exit(1);
6756
}
6857

@@ -88,35 +77,16 @@ int main (int argc, char * argv[])
8877
ULogger::setLevel(ULogger::kInfo);
8978

9079
// parse arguments
91-
QString fileName;
80+
std::string fileName;
9281
bool show = true;
93-
int driver = 0;
94-
std::string deviceId;
95-
float rate = 0.0f;
82+
std::string configFile;
9683

97-
if(argc < 2)
84+
if(argc < 3)
9885
{
9986
showUsage();
10087
}
101-
for(int i=1; i<argc-1; ++i)
88+
for(int i=1; i<argc-2; ++i)
10289
{
103-
if(strcmp(argv[i], "-rate") == 0)
104-
{
105-
++i;
106-
if(i < argc)
107-
{
108-
rate = uStr2Float(argv[i]);
109-
if(rate < 0.0f)
110-
{
111-
showUsage();
112-
}
113-
}
114-
else
115-
{
116-
showUsage();
117-
}
118-
continue;
119-
}
12090
if(strcmp(argv[i], "-debug") == 0)
12191
{
12292
ULogger::setLevel(ULogger::kDebug);
@@ -127,192 +97,86 @@ int main (int argc, char * argv[])
12797
show = false;
12898
continue;
12999
}
130-
if(strcmp(argv[i], "-driver") == 0)
131-
{
132-
++i;
133-
if(i < argc)
134-
{
135-
driver = std::atoi(argv[i]);
136-
if(driver < 0 || driver > 13)
137-
{
138-
showUsage();
139-
}
140-
}
141-
else
142-
{
143-
showUsage();
144-
}
145-
continue;
146-
}
147-
if(strcmp(argv[i], "-device") == 0)
148-
{
149-
++i;
150-
if(i < argc)
151-
{
152-
deviceId = argv[i];
153-
}
154-
else
155-
{
156-
showUsage();
157-
}
158-
continue;
159-
}
160-
161100
printf("Unrecognized option : %s\n", argv[i]);
162101
showUsage();
163102
}
103+
configFile = argv[argc-2];
104+
configFile = uReplaceChar(configFile, '~', UDirectory::homeDir());
164105
fileName = argv[argc-1]; // the last is the output path
106+
fileName = uReplaceChar(fileName, '~', UDirectory::homeDir());
165107

166-
if(UFile::getExtension(fileName.toStdString()).compare("db") != 0)
108+
if(UFile::getExtension(fileName).compare("db") != 0)
167109
{
168110
printf("Database names must end with .db extension\n");
169111
showUsage();
170112
}
171113

172-
UINFO("Output = %s", fileName.toStdString().c_str());
114+
UINFO("Output = %s", fileName.c_str());
173115
UINFO("Show = %s", show?"true":"false");
174-
UINFO("Rate =%f Hz", rate);
116+
UINFO("Config = %s", configFile.c_str());
175117

176118
app = new QApplication(argc, argv);
177119

120+
PreferencesDialog dialog;
121+
//Set working directory to default if not in config file to avoid message box
122+
ParametersMap paramTmp;
123+
Parameters::readINI(configFile, paramTmp);
124+
if(paramTmp.find(Parameters::kRtabmapWorkingDirectory()) == paramTmp.end())
125+
{
126+
paramTmp.clear();
127+
paramTmp.insert(ParametersPair(Parameters::kRtabmapWorkingDirectory(), dialog.getDefaultWorkingDirectory().toStdString()));
128+
Parameters::writeINI(configFile, paramTmp);
129+
}
130+
dialog.init(configFile.c_str());
131+
132+
UINFO("Driver = %d", dialog.getSourceDriver());
133+
UINFO("Rate = %f Hz", dialog.getGeneralInputRate());
134+
178135
// Catch ctrl-c to close the gui
179136
// (Place this after QApplication's constructor)
180137
signal(SIGABRT, &sighandler);
181138
signal(SIGTERM, &sighandler);
182139
signal(SIGINT, &sighandler);
183140

184-
rtabmap::Camera * camera = 0;
185-
if(driver == 0)
186-
{
187-
camera = new rtabmap::CameraOpenni(deviceId, rate);
188-
}
189-
else if(driver == 1)
141+
rtabmap::Camera * camera = dialog.createCamera();
142+
if(camera == 0)
190143
{
191-
if(!rtabmap::CameraOpenNI2::available())
192-
{
193-
UERROR("Not built with OpenNI2 support...");
194-
exit(-1);
195-
}
196-
camera = new rtabmap::CameraOpenNI2(deviceId, CameraOpenNI2::kTypeColorDepth, rate);
197-
}
198-
else if(driver == 2)
199-
{
200-
if(!rtabmap::CameraFreenect::available())
201-
{
202-
UERROR("Not built with Freenect support...");
203-
exit(-1);
204-
}
205-
camera = new rtabmap::CameraFreenect(deviceId.size()?atoi(deviceId.c_str()):0, CameraFreenect::kTypeColorDepth, rate);
206-
}
207-
else if(driver == 3)
208-
{
209-
if(!rtabmap::CameraOpenNICV::available())
210-
{
211-
UERROR("Not built with OpenNI from OpenCV support...");
212-
exit(-1);
213-
}
214-
camera = new rtabmap::CameraOpenNICV(false, rate);
215-
}
216-
else if(driver == 4)
217-
{
218-
if(!rtabmap::CameraOpenNICV::available())
219-
{
220-
UERROR("Not built with OpenNI from OpenCV support...");
221-
exit(-1);
222-
}
223-
camera = new rtabmap::CameraOpenNICV(true, rate);
144+
return -1;
224145
}
225-
else if(driver == 5)
146+
ParametersMap parameters = dialog.getAllParameters();
147+
cam = new CameraThread(camera, parameters);
148+
cam->setMirroringEnabled(dialog.isSourceMirroring());
149+
cam->setColorOnly(dialog.isSourceRGBDColorOnly());
150+
cam->setImageDecimation(dialog.getSourceImageDecimation());
151+
cam->setStereoToDepth(dialog.isSourceStereoDepthGenerated());
152+
cam->setStereoExposureCompensation(dialog.isSourceStereoExposureCompensation());
153+
cam->setScanParameters(
154+
dialog.isSourceScanFromDepth(),
155+
dialog.getSourceScanDownsampleStep(),
156+
dialog.getSourceScanRangeMin(),
157+
dialog.getSourceScanRangeMax(),
158+
dialog.getSourceScanVoxelSize(),
159+
dialog.getSourceScanNormalsK(),
160+
dialog.getSourceScanNormalsRadius(),
161+
(float)dialog.getSourceScanForceGroundNormalsUp());
162+
if(dialog.getIMUFilteringStrategy()>0 && dynamic_cast<DBReader*>(camera) == 0)
226163
{
227-
if(!rtabmap::CameraFreenect2::available())
228-
{
229-
UERROR("Not built with Freenect2 support...");
230-
exit(-1);
231-
}
232-
camera = new rtabmap::CameraFreenect2(deviceId.size()?atoi(deviceId.c_str()):0, rtabmap::CameraFreenect2::kTypeColor2DepthSD, rate);
164+
cam->enableIMUFiltering(dialog.getIMUFilteringStrategy()-1, parameters);
233165
}
234-
else if(driver == 6)
166+
if(dialog.isDepthFilteringAvailable())
235167
{
236-
if(!rtabmap::CameraStereoDC1394::available())
168+
if(dialog.isBilateralFiltering())
237169
{
238-
UERROR("Not built with dc1394 support...");
239-
exit(-1);
170+
cam->enableBilateralFiltering(
171+
dialog.getBilateralSigmaS(),
172+
dialog.getBilateralSigmaR());
240173
}
241-
camera = new rtabmap::CameraStereoDC1394(rate);
242-
}
243-
else if(driver == 7)
244-
{
245-
if(!rtabmap::CameraStereoFlyCapture2::available())
246-
{
247-
UERROR("Not built with FlyCapture2/Triclops support...");
248-
exit(-1);
249-
}
250-
camera = new rtabmap::CameraStereoFlyCapture2(rate);
251-
}
252-
else if(driver == 8)
253-
{
254-
if(!rtabmap::CameraStereoZed::available())
255-
{
256-
UERROR("Not built with ZED sdk support...");
257-
exit(-1);
258-
}
259-
camera = new rtabmap::CameraStereoZed(uStr2Int(deviceId));
260-
}
261-
else if (driver == 9)
262-
{
263-
if (!rtabmap::CameraRealSense::available())
264-
{
265-
UERROR("Not built with RealSense support...");
266-
exit(-1);
267-
}
268-
camera = new rtabmap::CameraRealSense(uStr2Int(deviceId));
269-
}
270-
else if (driver == 10)
271-
{
272-
if (!rtabmap::CameraK4W2::available())
273-
{
274-
UERROR("Not built with Kinect for Windows 2 SDK support...");
275-
exit(-1);
276-
}
277-
camera = new rtabmap::CameraK4W2(uStr2Int(deviceId));
278-
}
279-
else if (driver == 11)
280-
{
281-
if (!rtabmap::CameraRealSense2::available())
282-
{
283-
UERROR("Not built with RealSense2 SDK support...");
284-
exit(-1);
285-
}
286-
camera = new rtabmap::CameraRealSense2(deviceId);
287-
}
288-
else if (driver == 12)
289-
{
290-
if (!rtabmap::CameraK4A::available())
291-
{
292-
UERROR("Not built with Kinect for Azure SDK support...");
293-
exit(-1);
294-
}
295-
camera = new rtabmap::CameraK4A(1);
296-
}
297-
else if (driver == 13)
298-
{
299-
if (!rtabmap::CameraMyntEye::available())
300-
{
301-
UERROR("Not built with Mynt Eye S support...");
302-
exit(-1);
303-
}
304-
camera = new rtabmap::CameraMyntEye(deviceId);
305-
}
306-
else
307-
{
308-
UFATAL("Camera driver (%d) not found!", driver);
174+
cam->setDistortionModel(dialog.getSourceDistortionModel().toStdString());
309175
}
310-
cam = new CameraThread(camera);
311-
cam->enableIMUFiltering();
312176

313177
DataRecorder recorder;
314178

315-
if(recorder.init(fileName))
179+
if(recorder.init(fileName.c_str()))
316180
{
317181
recorder.registerToEventsManager();
318182
if(show)
@@ -341,7 +205,7 @@ int main (int argc, char * argv[])
341205
}
342206
else
343207
{
344-
UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.toStdString().c_str());
208+
UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.c_str());
345209
}
346210

347211
if(cam)

0 commit comments

Comments
 (0)