tools/DataRecorder/main.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions 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 the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
29 #include <rtabmap/utilite/UFile.h>
34 #include <rtabmap/core/Camera.h>
35 #include <rtabmap/core/DBReader.h>
39 #include <QApplication>
40 #include <signal.h>
41 
42 using namespace rtabmap;
43 
44 void showUsage()
45 {
46  printf("\nUsage:\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"
52  "Options:\n"
53  " -debug Show debug log.\n"
54  " -hide Don't display the current cloud recorded.\n");
55  exit(1);
56 }
57 
59 QApplication * app = 0;
60 // catch ctrl-c
61 void sighandler(int sig)
62 {
63  printf("\nSignal %d caught...\n", sig);
64  if(cam)
65  {
66  cam->join(true);
67  }
68  if(app)
69  {
70  QMetaObject::invokeMethod(app, "quit");
71  }
72 }
73 
74 int main (int argc, char * argv[])
75 {
78 
79  // parse arguments
80  std::string fileName;
81  bool show = true;
82  std::string configFile;
83 
84  if(argc < 3)
85  {
86  showUsage();
87  }
88  for(int i=1; i<argc-2; ++i)
89  {
90  if(strcmp(argv[i], "-debug") == 0)
91  {
93  continue;
94  }
95  if(strcmp(argv[i], "-hide") == 0)
96  {
97  show = false;
98  continue;
99  }
100  printf("Unrecognized option : %s\n", argv[i]);
101  showUsage();
102  }
103  configFile = argv[argc-2];
104  configFile = uReplaceChar(configFile, '~', UDirectory::homeDir());
105  fileName = argv[argc-1]; // the last is the output path
106  fileName = uReplaceChar(fileName, '~', UDirectory::homeDir());
107 
108  if(UFile::getExtension(fileName).compare("db") != 0)
109  {
110  printf("Database names must end with .db extension\n");
111  showUsage();
112  }
113 
114  UINFO("Output = %s", fileName.c_str());
115  UINFO("Show = %s", show?"true":"false");
116  UINFO("Config = %s", configFile.c_str());
117 
118  app = new QApplication(argc, argv);
119 
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 
135  // Catch ctrl-c to close the gui
136  // (Place this after QApplication's constructor)
137  signal(SIGABRT, &sighandler);
138  signal(SIGTERM, &sighandler);
139  signal(SIGINT, &sighandler);
140 
141  rtabmap::Camera * camera = dialog.createCamera();
142  if(camera == 0)
143  {
144  return -1;
145  }
146  ParametersMap parameters = dialog.getAllParameters();
147  cam = new CameraThread(camera, parameters);
148  cam->setMirroringEnabled(dialog.isSourceMirroring());
149  cam->setColorOnly(dialog.isSourceRGBDColorOnly());
153  cam->setScanParameters(
154  dialog.isSourceScanFromDepth(),
156  dialog.getSourceScanRangeMin(),
157  dialog.getSourceScanRangeMax(),
158  dialog.getSourceScanVoxelSize(),
159  dialog.getSourceScanNormalsK(),
161  (float)dialog.getSourceScanForceGroundNormalsUp());
162  if(dialog.getIMUFilteringStrategy()>0 && dynamic_cast<DBReader*>(camera) == 0)
163  {
165  }
166  if(dialog.isDepthFilteringAvailable())
167  {
168  if(dialog.isBilateralFiltering())
169  {
171  dialog.getBilateralSigmaS(),
172  dialog.getBilateralSigmaR());
173  }
174  cam->setDistortionModel(dialog.getSourceDistortionModel().toStdString());
175  }
176 
177  DataRecorder recorder;
178 
179  if(recorder.init(fileName.c_str()))
180  {
181  recorder.registerToEventsManager();
182  if(show)
183  {
184  recorder.setWindowTitle("Data recorder");
185  recorder.setMinimumWidth(500);
186  recorder.setMinimumHeight(300);
187  recorder.showNormal();
188  app->processEvents();
189  }
190 
191  if(camera->init())
192  {
193  cam->start();
194 
195  app->exec();
196 
197  UINFO("Closing...");
198 
199  recorder.close();
200  }
201  else
202  {
203  UERROR("Cannot initialize the camera!");
204  }
205  }
206  else
207  {
208  UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.c_str());
209  }
210 
211  if(cam)
212  {
213  delete cam;
214  }
215 
216  return 0;
217 }
static std::string homeDir()
Definition: UDirectory.cpp:355
void sighandler(int sig)
rtabmap::CameraThread * cam
Camera * createCamera(bool useRawImages=false, bool useColor=true)
void start()
Definition: UThread.cpp:122
void setStereoExposureCompensation(bool enabled)
Definition: CameraThread.h:80
rtabmap::ParametersMap getAllParameters() const
virtual QString getDefaultWorkingDirectory() const
std::pair< std::string, std::string > ParametersPair
Definition: Parameters.h:44
void enableBilateralFiltering(float sigmaS, float sigmaR)
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
static void writeINI(const std::string &configFile, const ParametersMap &parameters)
Some conversion functions.
int main(int argc, char *argv[])
std::string getExtension()
Definition: UFile.h:140
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
bool getIMUFilteringBaseFrameConversion() const
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
void setColorOnly(bool colorOnly)
Definition: CameraThread.h:81
void setScanParameters(bool fromDepth, int downsampleStep=1, float rangeMin=0.0f, float rangeMax=0.0f, float voxelSize=0.0f, int normalsK=0, int normalsRadius=0.0f, float groundNormalsUp=0.0f)
void enableIMUFiltering(int filteringStrategy=1, const ParametersMap &parameters=ParametersMap(), bool baseFrameConversion=false)
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
void init(const QString &iniFilePath="")
std::string UTILITE_EXP uReplaceChar(const std::string &str, char before, char after)
Definition: UConversion.cpp:33
void setDistortionModel(const std::string &path)
void setMirroringEnabled(bool enabled)
Definition: CameraThread.h:79
void setImageDecimation(int decimation)
Definition: CameraThread.h:82
void registerToEventsManager()
QApplication * app
void setStereoToDepth(bool enabled)
Definition: CameraThread.h:83
QString getSourceDistortionModel() const
PreferencesDialog::Src getSourceDriver() const
#define UERROR(...)
double getSourceScanForceGroundNormalsUp() const
ULogger class and convenient macros.
static void readINI(const std::string &configFile, ParametersMap &parameters, bool modifiedOnly=false)
bool init(const QString &path, bool recordInRAM=true)
void join(bool killFirst=false)
Definition: UThread.cpp:85
void showUsage()
bool isSourceStereoExposureCompensation() const
#define UINFO(...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:29