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  " --device # Device id\n"
52  " --debug Debug log\n"
53  " --stereo Stereo: assuming device provides \n"
54  " side-by-side stereo images, otherwise \n"
55  " add also \"--device_r #\" for the right device.\n\n");
56  exit(1);
57 }
58 
59 int main(int argc, char * argv[])
60 {
63  ULogger::setPrintTime(false);
65 
66  int driver = -1;
67  int device = 0;
68  int deviceRight = -1;
69  bool stereo = false;
70  for(int i=1; i<argc; ++i)
71  {
72  if(strcmp(argv[i], "--driver") == 0)
73  {
74  ++i;
75  if(i < argc)
76  {
77  driver = std::atoi(argv[i]);
78  if(driver < -1)
79  {
80  showUsage();
81  }
82  }
83  else
84  {
85  showUsage();
86  }
87  continue;
88  }
89  if(strcmp(argv[i], "--device") == 0)
90  {
91  ++i;
92  if(i < argc)
93  {
94  device = std::atoi(argv[i]);
95  if(device < 0)
96  {
97  showUsage();
98  }
99  }
100  else
101  {
102  showUsage();
103  }
104  continue;
105  }
106  if(strcmp(argv[i], "--device_r") == 0)
107  {
108  ++i;
109  if(i < argc)
110  {
111  deviceRight = std::atoi(argv[i]);
112  if(deviceRight < 0)
113  {
114  showUsage();
115  }
116  }
117  else
118  {
119  showUsage();
120  }
121  continue;
122  }
123  if(strcmp(argv[i], "--debug") == 0)
124  {
126  ULogger::setPrintTime(true);
128  continue;
129  }
130  if(strcmp(argv[i], "--stereo") == 0)
131  {
132  stereo=true;
133  continue;
134  }
135  if(strcmp(argv[i], "--help") == 0)
136  {
137  showUsage();
138  }
139  printf("Unrecognized option : %s\n", argv[i]);
140  showUsage();
141  }
142  if(driver < -1 || driver > 7)
143  {
144  UERROR("driver should be between -1 and 7.");
145  showUsage();
146  }
147 
148  UINFO("Using driver %d", driver);
149  UINFO("Using device %d", device);
150  UINFO("Stereo: %s", stereo?"true":"false");
151  if(stereo && deviceRight >= 0)
152  {
153  UINFO("Using right device %d", deviceRight);
154  }
155 
156  QApplication app(argc, argv);
157  rtabmap::CalibrationDialog dialog(stereo, ".");
158 
159  rtabmap::Camera * camera = 0;
160  if(driver == -1)
161  {
162  if(stereo)
163  {
164  if(deviceRight>=0)
165  {
166  // left and right videos
167  camera = new rtabmap::CameraStereoVideo(device, deviceRight);
168  }
169  else
170  {
171  // side-by-side video
172  camera = new rtabmap::CameraStereoVideo(device);
173  }
174  }
175  else
176  {
177  camera = new rtabmap::CameraVideo(device);
178  }
179  dialog.setStereoMode(stereo);
180  }
181  else if(driver == 0)
182  {
183  camera = new rtabmap::CameraOpenni();
184  }
185  else if(driver == 1)
186  {
188  {
189  UERROR("Not built with OpenNI2 support...");
190  exit(-1);
191  }
192  camera = new rtabmap::CameraOpenNI2();
193  }
194  else if(driver == 2)
195  {
197  {
198  UERROR("Not built with Freenect support...");
199  exit(-1);
200  }
201  camera = new rtabmap::CameraFreenect();
202  }
203  else if(driver == 3)
204  {
206  {
207  UERROR("Not built with OpenNI from OpenCV support...");
208  exit(-1);
209  }
210  camera = new rtabmap::CameraOpenNICV(false);
211  }
212  else if(driver == 4)
213  {
215  {
216  UERROR("Not built with OpenNI from OpenCV support...");
217  exit(-1);
218  }
219  camera = new rtabmap::CameraOpenNICV(true);
220  }
221  else if(driver == 5)
222  {
224  {
225  UERROR("Not built with Freenect2 support...");
226  exit(-1);
227  }
229  dialog.setSwitchedImages(true);
230  dialog.setStereoMode(stereo, "rgb", "depth");
231  }
232  else if(driver == 6)
233  {
235  {
236  UERROR("Not built with DC1394 support...");
237  exit(-1);
238  }
239  camera = new rtabmap::CameraStereoDC1394();
240  dialog.setStereoMode(stereo);
241  }
242  else if(driver == 7)
243  {
245  {
246  UERROR("Not built with FlyCapture2/Triclops support...");
247  exit(-1);
248  }
249  camera = new rtabmap::CameraStereoFlyCapture2();
250  dialog.setStereoMode(stereo);
251  }
252  else
253  {
254  UFATAL("");
255  }
256 
257  rtabmap::CameraThread * cameraThread = 0;
258 
259  if(camera)
260  {
261  if(!camera->init(""))
262  {
263  printf("Camera init failed!\n");
264  delete camera;
265  exit(1);
266  }
267  cameraThread = new rtabmap::CameraThread(camera);
268  }
269 
270  dialog.registerToEventsManager();
271 
272  dialog.show();
273  cameraThread->start();
274  app.exec();
275  cameraThread->join(true);
276  delete cameraThread;
277 }
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
#define UINFO(...)


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