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  " 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");
66  exit(1);
67 }
68 
70 QApplication * app = 0;
71 // catch ctrl-c
72 void sighandler(int sig)
73 {
74  printf("\nSignal %d caught...\n", sig);
75  if(cam)
76  {
77  cam->join(true);
78  }
79  if(app)
80  {
81  QMetaObject::invokeMethod(app, "quit");
82  }
83 }
84 
85 int main (int argc, char * argv[])
86 {
89 
90  // parse arguments
91  QString fileName;
92  bool show = true;
93  int driver = 0;
94  std::string deviceId;
95  float rate = 0.0f;
96 
97  if(argc < 2)
98  {
99  showUsage();
100  }
101  for(int i=1; i<argc-1; ++i)
102  {
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  }
120  if(strcmp(argv[i], "-debug") == 0)
121  {
123  continue;
124  }
125  if(strcmp(argv[i], "-hide") == 0)
126  {
127  show = false;
128  continue;
129  }
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 
161  printf("Unrecognized option : %s\n", argv[i]);
162  showUsage();
163  }
164  fileName = argv[argc-1]; // the last is the output path
165 
166  if(UFile::getExtension(fileName.toStdString()).compare("db") != 0)
167  {
168  printf("Database names must end with .db extension\n");
169  showUsage();
170  }
171 
172  UINFO("Output = %s", fileName.toStdString().c_str());
173  UINFO("Show = %s", show?"true":"false");
174  UINFO("Rate =%f Hz", rate);
175 
176  app = new QApplication(argc, argv);
177 
178  // Catch ctrl-c to close the gui
179  // (Place this after QApplication's constructor)
180  signal(SIGABRT, &sighandler);
181  signal(SIGTERM, &sighandler);
182  signal(SIGINT, &sighandler);
183 
184  rtabmap::Camera * camera = 0;
185  if(driver == 0)
186  {
187  camera = new rtabmap::CameraOpenni(deviceId, rate);
188  }
189  else if(driver == 1)
190  {
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  {
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  {
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  {
219  {
220  UERROR("Not built with OpenNI from OpenCV support...");
221  exit(-1);
222  }
223  camera = new rtabmap::CameraOpenNICV(true, rate);
224  }
225  else if(driver == 5)
226  {
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);
233  }
234  else if(driver == 6)
235  {
237  {
238  UERROR("Not built with dc1394 support...");
239  exit(-1);
240  }
241  camera = new rtabmap::CameraStereoDC1394(rate);
242  }
243  else if(driver == 7)
244  {
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  {
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  {
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  {
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  {
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  {
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  {
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);
309  }
310  cam = new CameraThread(camera);
311  cam->enableIMUFiltering();
312 
313  DataRecorder recorder;
314 
315  if(recorder.init(fileName))
316  {
317  recorder.registerToEventsManager();
318  if(show)
319  {
320  recorder.setWindowTitle("Data recorder");
321  recorder.setMinimumWidth(500);
322  recorder.setMinimumHeight(300);
323  recorder.showNormal();
324  app->processEvents();
325  }
326 
327  if(camera->init())
328  {
329  cam->start();
330 
331  app->exec();
332 
333  UINFO("Closing...");
334 
335  recorder.close();
336  }
337  else
338  {
339  UERROR("Cannot initialize the camera!");
340  }
341  }
342  else
343  {
344  UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.toStdString().c_str());
345  }
346 
347  if(cam)
348  {
349  delete cam;
350  }
351 
352  return 0;
353 }
int UTILITE_EXP uStr2Int(const std::string &str)
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 void setLevel(ULogger::Level level)
Definition: ULogger.h:339
#define UFATAL(...)
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.
static bool available()
Definition: CameraK4A.cpp:42
bool init(const QString &path, bool recordInRAM=true)
void join(bool killFirst=false)
Definition: UThread.cpp:85
static bool available()
Definition: CameraK4W2.cpp:53
void showUsage()
void enableIMUFiltering(int filteringStrategy=1, const ParametersMap &parameters=ParametersMap())
#define UINFO(...)


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:34:59