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>
37 #include <QApplication>
38 #include <signal.h>
39 
40 using namespace rtabmap;
41 
42 void showUsage()
43 {
44  printf("\nUsage:\n"
45  "dataRecorder [options] output.db\n"
46  "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  " -device "" Device ID (default \"\")\n");
60  exit(1);
61 }
62 
64 QApplication * app = 0;
65 // catch ctrl-c
66 void sighandler(int sig)
67 {
68  printf("\nSignal %d caught...\n", sig);
69  if(cam)
70  {
71  cam->join(true);
72  }
73  if(app)
74  {
75  QMetaObject::invokeMethod(app, "quit");
76  }
77 }
78 
79 int main (int argc, char * argv[])
80 {
83 
84  // parse arguments
85  QString fileName;
86  bool show = true;
87  int driver = 0;
88  std::string deviceId;
89  float rate = 0.0f;
90 
91  if(argc < 2)
92  {
93  showUsage();
94  }
95  for(int i=1; i<argc-1; ++i)
96  {
97  if(strcmp(argv[i], "-rate") == 0)
98  {
99  ++i;
100  if(i < argc)
101  {
102  rate = uStr2Float(argv[i]);
103  if(rate < 0.0f)
104  {
105  showUsage();
106  }
107  }
108  else
109  {
110  showUsage();
111  }
112  continue;
113  }
114  if(strcmp(argv[i], "-debug") == 0)
115  {
117  continue;
118  }
119  if(strcmp(argv[i], "-hide") == 0)
120  {
121  show = false;
122  continue;
123  }
124  if(strcmp(argv[i], "-driver") == 0)
125  {
126  ++i;
127  if(i < argc)
128  {
129  driver = std::atoi(argv[i]);
130  if(driver < 0 || driver > 7)
131  {
132  showUsage();
133  }
134  }
135  else
136  {
137  showUsage();
138  }
139  continue;
140  }
141  if(strcmp(argv[i], "-device") == 0)
142  {
143  ++i;
144  if(i < argc)
145  {
146  deviceId = argv[i];
147  }
148  else
149  {
150  showUsage();
151  }
152  continue;
153  }
154 
155  printf("Unrecognized option : %s\n", argv[i]);
156  showUsage();
157  }
158  fileName = argv[argc-1]; // the last is the output path
159 
160  if(UFile::getExtension(fileName.toStdString()).compare("db") != 0)
161  {
162  printf("Database names must end with .db extension\n");
163  showUsage();
164  }
165 
166  UINFO("Output = %s", fileName.toStdString().c_str());
167  UINFO("Show = %s", show?"true":"false");
168  UINFO("Rate =%f Hz", rate);
169 
170  app = new QApplication(argc, argv);
171 
172  // Catch ctrl-c to close the gui
173  // (Place this after QApplication's constructor)
174  signal(SIGABRT, &sighandler);
175  signal(SIGTERM, &sighandler);
176  signal(SIGINT, &sighandler);
177 
178  rtabmap::Camera * camera = 0;
179  rtabmap::Transform t=rtabmap::Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0);
180  if(driver == 0)
181  {
182  camera = new rtabmap::CameraOpenni(deviceId, rate, t);
183  }
184  else if(driver == 1)
185  {
187  {
188  UERROR("Not built with OpenNI2 support...");
189  exit(-1);
190  }
191  camera = new rtabmap::CameraOpenNI2(deviceId, CameraOpenNI2::kTypeColorDepth, rate, t);
192  }
193  else if(driver == 2)
194  {
196  {
197  UERROR("Not built with Freenect support...");
198  exit(-1);
199  }
200  camera = new rtabmap::CameraFreenect(deviceId.size()?atoi(deviceId.c_str()):0, CameraFreenect::kTypeColorDepth, rate, t);
201  }
202  else if(driver == 3)
203  {
205  {
206  UERROR("Not built with OpenNI from OpenCV support...");
207  exit(-1);
208  }
209  camera = new rtabmap::CameraOpenNICV(false, rate, t);
210  }
211  else if(driver == 4)
212  {
214  {
215  UERROR("Not built with OpenNI from OpenCV support...");
216  exit(-1);
217  }
218  camera = new rtabmap::CameraOpenNICV(true, rate, t);
219  }
220  else if(driver == 5)
221  {
223  {
224  UERROR("Not built with Freenect2 support...");
225  exit(-1);
226  }
227  camera = new rtabmap::CameraFreenect2(deviceId.size()?atoi(deviceId.c_str()):0, rtabmap::CameraFreenect2::kTypeColor2DepthSD, rate, t);
228  }
229  else if(driver == 6)
230  {
232  {
233  UERROR("Not built with dc1394 support...");
234  exit(-1);
235  }
236  camera = new rtabmap::CameraStereoDC1394(rate, t);
237  }
238  else if(driver == 7)
239  {
241  {
242  UERROR("Not built with FlyCapture2/Triclops support...");
243  exit(-1);
244  }
245  camera = new rtabmap::CameraStereoFlyCapture2(rate, t);
246  }
247  else
248  {
249  UFATAL("Camera driver (%d) not found!", driver);
250  }
251  cam = new CameraThread(camera);
252 
253  DataRecorder recorder;
254 
255  if(recorder.init(fileName))
256  {
257  recorder.registerToEventsManager();
258  if(show)
259  {
260  recorder.setWindowTitle("Data recorder");
261  recorder.setMinimumWidth(500);
262  recorder.setMinimumHeight(300);
263  recorder.showNormal();
264  app->processEvents();
265  }
266 
267  if(camera->init())
268  {
269  cam->start();
270 
271  app->exec();
272 
273  UINFO("Closing...");
274 
275  recorder.close();
276  }
277  else
278  {
279  UERROR("Cannot initialize the camera!");
280  }
281  }
282  else
283  {
284  UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.toStdString().c_str());
285  }
286 
287  if(cam)
288  {
289  delete cam;
290  }
291 
292  return 0;
293 }
void sighandler(int sig)
rtabmap::CameraThread * cam
void start()
Definition: UThread.cpp:122
f
float UTILITE_EXP uStr2Float(const std::string &str)
Some conversion functions.
int main(int argc, char *argv[])
std::string getExtension()
Definition: UFile.h:140
static bool available()
Definition: CameraRGBD.cpp:382
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
#define UFATAL(...)
static bool available()
Definition: CameraRGBD.cpp:272
virtual bool init(const std::string &calibrationFolder=".", const std::string &cameraName="")=0
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
void registerToEventsManager()
QApplication * app
#define UERROR(...)
ULogger class and convenient macros.
bool init(const QString &path, bool recordInRAM=true)
void join(bool killFirst=false)
Definition: UThread.cpp:85
void showUsage()
#define UINFO(...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:31