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>
33 #include <rtabmap/core/Camera.h>
34 #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 SensorCaptureThread(camera, parameters);
155  dialog.isSourceScanFromDepth(),
157  dialog.getSourceScanRangeMin(),
158  dialog.getSourceScanRangeMax(),
159  dialog.getSourceScanVoxelSize(),
160  dialog.getSourceScanNormalsK(),
162  (float)dialog.getSourceScanForceGroundNormalsUp());
163  if(dialog.getIMUFilteringStrategy()>0 && dynamic_cast<DBReader*>(camera) == 0)
164  {
166  }
167  if(dialog.isDepthFilteringAvailable())
168  {
169  if(dialog.isBilateralFiltering())
170  {
172  dialog.getBilateralSigmaS(),
173  dialog.getBilateralSigmaR());
174  }
175  cam->setDistortionModel(dialog.getSourceDistortionModel().toStdString());
176  }
177 
178  DataRecorder recorder;
179 
180  if(recorder.init(fileName.c_str()))
181  {
182  recorder.registerToEventsManager();
183  if(show)
184  {
185  recorder.setWindowTitle("Data recorder");
186  recorder.setMinimumWidth(500);
187  recorder.setMinimumHeight(300);
188  recorder.showNormal();
189  app->processEvents();
190  }
191 
192  if(camera->init())
193  {
194  cam->start();
195 
196  app->exec();
197 
198  UINFO("Closing...");
199 
200  recorder.close();
201  }
202  else
203  {
204  UERROR("Cannot initialize the camera!");
205  }
206  }
207  else
208  {
209  UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.c_str());
210  }
211 
212  if(cam)
213  {
214  delete cam;
215  }
216 
217  return 0;
218 }
rtabmap::SensorCaptureThread
Definition: SensorCaptureThread.h:58
rtabmap::ParametersPair
std::pair< std::string, std::string > ParametersPair
Definition: Parameters.h:44
compare
bool compare
UINFO
#define UINFO(...)
rtabmap::PreferencesDialog::getSourceScanForceGroundNormalsUp
double getSourceScanForceGroundNormalsUp() const
Definition: PreferencesDialog.cpp:6399
rtabmap::PreferencesDialog::isSourceRGBDColorOnly
bool isSourceRGBDColorOnly() const
Definition: PreferencesDialog.cpp:6315
SensorCaptureThread.h
rtabmap::SensorCaptureThread::setScanParameters
RTABMAP_DEPRECATED void setScanParameters(bool fromDepth, int downsampleStep, float rangeMin, float rangeMax, float voxelSize, int normalsK, float normalsRadius, bool forceGroundNormalsUp, bool deskewing)
Definition: SensorCaptureThread.cpp:262
rtabmap::PreferencesDialog::isSourceStereoExposureCompensation
bool isSourceStereoExposureCompensation() const
Definition: PreferencesDialog.cpp:6363
rtabmap::DataRecorder::init
bool init(const QString &path, bool recordInRAM=true)
Definition: DataRecorder.cpp:67
UEventsHandler::registerToEventsManager
void registerToEventsManager()
Definition: UEventsHandler.cpp:29
rtabmap::PreferencesDialog::getAllParameters
rtabmap::ParametersMap getAllParameters() const
Definition: PreferencesDialog.cpp:4136
rtabmap::PreferencesDialog::getSourceScanNormalsRadius
double getSourceScanNormalsRadius() const
Definition: PreferencesDialog.cpp:6395
ULogger::kTypeConsole
@ kTypeConsole
Definition: ULogger.h:244
ULogger::setLevel
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
UThread::join
void join(bool killFirst=false)
Definition: UThread.cpp:85
rtabmap::SensorCaptureThread::setColorOnly
void setColorOnly(bool colorOnly)
Definition: SensorCaptureThread.h:125
ULogger::kDebug
@ kDebug
Definition: ULogger.h:252
CameraRGBD.h
rtabmap::PreferencesDialog::init
void init(const QString &iniFilePath="")
Definition: PreferencesDialog.cpp:1678
CameraStereo.h
rtabmap::PreferencesDialog::getBilateralSigmaR
double getBilateralSigmaR() const
Definition: PreferencesDialog.cpp:6343
DBReader.h
rtabmap::PreferencesDialog::getBilateralSigmaS
double getBilateralSigmaS() const
Definition: PreferencesDialog.cpp:6339
rtabmap::ParametersMap
std::map< std::string, std::string > ParametersMap
Definition: Parameters.h:43
rtabmap::PreferencesDialog::getSourceHistogramMethod
int getSourceHistogramMethod() const
Definition: PreferencesDialog.cpp:6351
cam
rtabmap::SensorCaptureThread * cam
Definition: tools/DataRecorder/main.cpp:58
rtabmap::SensorCaptureThread::setDistortionModel
void setDistortionModel(const std::string &path)
Definition: SensorCaptureThread.cpp:196
main
int main(int argc, char *argv[])
Definition: tools/DataRecorder/main.cpp:74
UDirectory::homeDir
static std::string homeDir()
Definition: UDirectory.cpp:355
rtabmap::DataRecorder
Definition: DataRecorder.h:46
rtabmap::PreferencesDialog::getDefaultWorkingDirectory
virtual QString getDefaultWorkingDirectory() const
Definition: PreferencesDialog.cpp:2859
rtabmap::SensorCapture::init
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
rtabmap::SensorCaptureThread::enableIMUFiltering
void enableIMUFiltering(int filteringStrategy=1, const ParametersMap &parameters=ParametersMap(), bool baseFrameConversion=false)
Definition: SensorCaptureThread.cpp:224
rtabmap::PreferencesDialog::isBilateralFiltering
bool isBilateralFiltering() const
Definition: PreferencesDialog.cpp:6335
rtabmap::PreferencesDialog::isSourceStereoDepthGenerated
bool isSourceStereoDepthGenerated() const
Definition: PreferencesDialog.cpp:6359
app
QApplication * app
Definition: tools/DataRecorder/main.cpp:59
rtabmap::PreferencesDialog::getSourceScanDownsampleStep
int getSourceScanDownsampleStep() const
Definition: PreferencesDialog.cpp:6375
UConversion.h
Some conversion functions.
UFile::getExtension
std::string getExtension()
Definition: UFile.h:140
rtabmap::PreferencesDialog::getGeneralInputRate
double getGeneralInputRate() const
Definition: PreferencesDialog.cpp:6163
ULogger::kInfo
@ kInfo
Definition: ULogger.h:252
rtabmap::SensorCaptureThread::setStereoExposureCompensation
void setStereoExposureCompensation(bool enabled)
Definition: SensorCaptureThread.h:124
rtabmap::PreferencesDialog::isSourceScanFromDepth
bool isSourceScanFromDepth() const
Definition: PreferencesDialog.cpp:6367
rtabmap::SensorCaptureThread::setMirroringEnabled
void setMirroringEnabled(bool enabled)
Definition: SensorCaptureThread.h:123
rtabmap_netvlad.argv
argv
Definition: rtabmap_netvlad.py:15
UThread::start
void start()
Definition: UThread.cpp:122
ULogger::setType
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
rtabmap::PreferencesDialog::getIMUFilteringStrategy
int getIMUFilteringStrategy() const
Definition: PreferencesDialog.cpp:6319
rtabmap::Camera
Definition: Camera.h:43
rtabmap::SensorCaptureThread::setStereoToDepth
void setStereoToDepth(bool enabled)
Definition: SensorCaptureThread.h:128
rtabmap::PreferencesDialog
Definition: PreferencesDialog.h:68
showUsage
void showUsage()
Definition: tools/DataRecorder/main.cpp:44
uReplaceChar
std::string UTILITE_EXPORT uReplaceChar(const std::string &str, char before, char after)
Definition: UConversion.cpp:33
PreferencesDialog.h
ULogger.h
ULogger class and convenient macros.
rtabmap::PreferencesDialog::getSourceImageDecimation
int getSourceImageDecimation() const
Definition: PreferencesDialog.cpp:6347
rtabmap::Parameters::readINI
static void readINI(const std::string &configFile, ParametersMap &parameters, bool modifiedOnly=false)
Definition: Parameters.cpp:1273
sighandler
void sighandler(int sig)
Definition: tools/DataRecorder/main.cpp:61
rtabmap::PreferencesDialog::getSourceScanNormalsK
int getSourceScanNormalsK() const
Definition: PreferencesDialog.cpp:6391
rtabmap::SensorCaptureThread::setImageDecimation
void setImageDecimation(int decimation)
Definition: SensorCaptureThread.h:126
camera
Camera camera(Pose3(Rot3().retract(Vector3(0.1, 0.2, 0.3)), Point3(0, 5, 0)), Cal3Bundler0(1, 0, 0))
rtabmap::PreferencesDialog::createCamera
Camera * createCamera(bool useRawImages=false, bool useColor=true)
Definition: PreferencesDialog.cpp:6404
rtabmap::PreferencesDialog::getSourceDistortionModel
QString getSourceDistortionModel() const
Definition: PreferencesDialog.cpp:6331
rtabmap::PreferencesDialog::getSourceScanRangeMax
double getSourceScanRangeMax() const
Definition: PreferencesDialog.cpp:6383
Camera.h
rtabmap::DBReader
Definition: DBReader.h:46
rtabmap::PreferencesDialog::getSourceScanVoxelSize
double getSourceScanVoxelSize() const
Definition: PreferencesDialog.cpp:6387
DataRecorder.h
rtabmap::PreferencesDialog::getSourceDriver
PreferencesDialog::Src getSourceDriver() const
Definition: PreferencesDialog.cpp:6192
rtabmap::PreferencesDialog::getIMUFilteringBaseFrameConversion
bool getIMUFilteringBaseFrameConversion() const
Definition: PreferencesDialog.cpp:6323
UFile.h
rtabmap
Definition: CameraARCore.cpp:35
rtabmap::SensorCaptureThread::setHistogramMethod
void setHistogramMethod(int histogramMethod)
Definition: SensorCaptureThread.h:127
UERROR
#define UERROR(...)
rtabmap::PreferencesDialog::getSourceScanRangeMin
double getSourceScanRangeMin() const
Definition: PreferencesDialog.cpp:6379
i
int i
rtabmap::PreferencesDialog::isSourceMirroring
bool isSourceMirroring() const
Definition: PreferencesDialog.cpp:6167
rtabmap::Parameters::writeINI
static void writeINI(const std::string &configFile, const ParametersMap &parameters)
Definition: Parameters.cpp:1287
rtabmap::SensorCaptureThread::enableBilateralFiltering
void enableBilateralFiltering(float sigmaS, float sigmaR)
Definition: SensorCaptureThread.cpp:216
rtabmap::PreferencesDialog::isDepthFilteringAvailable
bool isDepthFilteringAvailable() const
Definition: PreferencesDialog.cpp:6327


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:12