tools/Calibration/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 
28 #include "rtabmap/core/CameraRGB.h"
35 #include <QApplication>
36 
37 void showUsage()
38 {
39  printf("\nUsage:\n"
40  "rtabmap-calibration [options]\n"
41  "Options:\n"
42  " --driver # Driver number to use:-1=USB camera\n"
43  " 0=OpenNI-PCL (Kinect)\n"
44  " 1=OpenNI2 (Kinect and Xtion PRO Live)\n"
45  " 2=Freenect (Kinect)\n"
46  " 3=OpenNI-CV (Kinect)\n"
47  " 4=OpenNI-CV-ASUS (Xtion PRO Live)\n"
48  " 5=Freenect2 (Kinect v2)\n"
49  " 6=DC1394 (Bumblebee2)\n"
50  " 7=FlyCapture2 (Bumblebee2)\n"
51  " 11=RealSense2 (T265)\n"
52  " --device # Device id\n"
53  " --debug Debug log\n"
54  " --stereo Stereo: assuming device provides \n"
55  " side-by-side stereo images, otherwise \n"
56  " add also \"--device_r #\" for the right device.\n\n");
57  exit(1);
58 }
59 
60 int main(int argc, char * argv[])
61 {
64  ULogger::setPrintTime(false);
66 
67  int driver = -1;
68  int device = 0;
69  int deviceRight = -1;
70  bool stereo = false;
71  for(int i=1; i<argc; ++i)
72  {
73  if(strcmp(argv[i], "--driver") == 0)
74  {
75  ++i;
76  if(i < argc)
77  {
78  driver = std::atoi(argv[i]);
79  if(driver < -1)
80  {
81  showUsage();
82  }
83  }
84  else
85  {
86  showUsage();
87  }
88  continue;
89  }
90  if(strcmp(argv[i], "--device") == 0)
91  {
92  ++i;
93  if(i < argc)
94  {
95  device = std::atoi(argv[i]);
96  if(device < 0)
97  {
98  showUsage();
99  }
100  }
101  else
102  {
103  showUsage();
104  }
105  continue;
106  }
107  if(strcmp(argv[i], "--device_r") == 0)
108  {
109  ++i;
110  if(i < argc)
111  {
112  deviceRight = std::atoi(argv[i]);
113  if(deviceRight < 0)
114  {
115  showUsage();
116  }
117  }
118  else
119  {
120  showUsage();
121  }
122  continue;
123  }
124  if(strcmp(argv[i], "--debug") == 0)
125  {
127  ULogger::setPrintTime(true);
129  continue;
130  }
131  if(strcmp(argv[i], "--stereo") == 0)
132  {
133  stereo=true;
134  continue;
135  }
136  if(strcmp(argv[i], "--help") == 0)
137  {
138  showUsage();
139  }
140  printf("Unrecognized option : %s\n", argv[i]);
141  showUsage();
142  }
143  if(driver < -1 || driver > 15)
144  {
145  UERROR("driver should be between -1 and 15.");
146  showUsage();
147  }
148  if(driver == 11)
149  {
150  stereo = true;
151  }
152 
153  UINFO("Using driver %d", driver);
154  UINFO("Using device %d", device);
155  UINFO("Stereo: %s", stereo?"true":"false");
156  if(stereo && deviceRight >= 0)
157  {
158  UINFO("Using right device %d", deviceRight);
159  }
160 
161  QApplication app(argc, argv);
162  rtabmap::CalibrationDialog dialog(stereo, ".");
163 
164  rtabmap::Camera * camera = 0;
165  if(driver == -1)
166  {
167  if(stereo)
168  {
169  if(deviceRight>=0)
170  {
171  // left and right videos
172  camera = new rtabmap::CameraStereoVideo(device, deviceRight);
173  }
174  else
175  {
176  // side-by-side video
177  camera = new rtabmap::CameraStereoVideo(device);
178  }
179  }
180  else
181  {
182  camera = new rtabmap::CameraVideo(device);
183  }
184  dialog.setStereoMode(stereo);
185  }
186  else if(driver == 0)
187  {
188  camera = new rtabmap::CameraOpenni();
189  }
190  else if(driver == 1)
191  {
193  {
194  UERROR("Not built with OpenNI2 support...");
195  exit(-1);
196  }
197  camera = new rtabmap::CameraOpenNI2();
198  }
199  else if(driver == 2)
200  {
202  {
203  UERROR("Not built with Freenect support...");
204  exit(-1);
205  }
206  camera = new rtabmap::CameraFreenect();
207  }
208  else if(driver == 3)
209  {
211  {
212  UERROR("Not built with OpenNI from OpenCV support...");
213  exit(-1);
214  }
215  camera = new rtabmap::CameraOpenNICV(false);
216  }
217  else if(driver == 4)
218  {
220  {
221  UERROR("Not built with OpenNI from OpenCV support...");
222  exit(-1);
223  }
224  camera = new rtabmap::CameraOpenNICV(true);
225  }
226  else if(driver == 5)
227  {
229  {
230  UERROR("Not built with Freenect2 support...");
231  exit(-1);
232  }
234  dialog.setSwitchedImages(true);
235  dialog.setStereoMode(stereo, "rgb", "depth");
236  }
237  else if(driver == 6)
238  {
240  {
241  UERROR("Not built with DC1394 support...");
242  exit(-1);
243  }
244  camera = new rtabmap::CameraStereoDC1394();
245  dialog.setStereoMode(stereo);
246  }
247  else if(driver == 7)
248  {
250  {
251  UERROR("Not built with FlyCapture2/Triclops support...");
252  exit(-1);
253  }
254  camera = new rtabmap::CameraStereoFlyCapture2();
255  dialog.setStereoMode(stereo);
256  }
257  else if(driver == 11)
258  {
260  {
261  UERROR("Not built with RealSense2 support...");
262  exit(-1);
263  }
264  camera = new rtabmap::CameraRealSense2();
265  ((rtabmap::CameraRealSense2*)camera)->setImagesRectified(false);
266  dialog.setStereoMode(true);
267  dialog.setFisheyeImages(true);
268  }
269  else
270  {
271  UFATAL("Calibration for driver %d not available.", driver);
272  }
273 
274  rtabmap::CameraThread * cameraThread = 0;
275 
276  if(camera)
277  {
278  if(!camera->init(""))
279  {
280  printf("Camera init failed!\n");
281  delete camera;
282  exit(1);
283  }
284  cameraThread = new rtabmap::CameraThread(camera);
285  }
286 
287  dialog.registerToEventsManager();
288 
289  dialog.show();
290  cameraThread->start();
291  app.exec();
292  cameraThread->join(true);
293  delete cameraThread;
294 }
void start()
Definition: UThread.cpp:122
Some conversion functions.
void setSwitchedImages(bool switched)
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 setPrintTime(bool printTime)
Definition: ULogger.h:273
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
static void setPrintWhere(bool printWhere)
Definition: ULogger.h:302
void registerToEventsManager()
QApplication * app
void setStereoMode(bool stereo, const QString &leftSuffix="left", const QString &rightSuffix="right")
int main(int argc, char *argv[])
void showUsage()
#define UERROR(...)
ULogger class and convenient macros.
void join(bool killFirst=false)
Definition: UThread.cpp:85
void setFisheyeImages(bool enabled)
#define UINFO(...)


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