main.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include "rtabmap/core/CameraRGB.h"
00029 #include "rtabmap/core/CameraRGBD.h"
00030 #include "rtabmap/core/CameraStereo.h"
00031 #include "rtabmap/core/CameraThread.h"
00032 #include "rtabmap/utilite/ULogger.h"
00033 #include "rtabmap/utilite/UConversion.h"
00034 #include "rtabmap/gui/CalibrationDialog.h"
00035 #include <QApplication>
00036 
00037 void showUsage()
00038 {
00039         printf("\nUsage:\n"
00040                         "rtabmap-calibration [options]\n"
00041                         "Options:\n"
00042                         "  --driver #     Driver number to use:-1=USB camera\n"
00043                         "                                       0=OpenNI-PCL (Kinect)\n"
00044                         "                                       1=OpenNI2    (Kinect and Xtion PRO Live)\n"
00045                         "                                       2=Freenect   (Kinect)\n"
00046                         "                                       3=OpenNI-CV  (Kinect)\n"
00047                         "                                       4=OpenNI-CV-ASUS (Xtion PRO Live)\n"
00048                         "                                       5=Freenect2  (Kinect v2)\n"
00049                         "                                       6=DC1394     (Bumblebee2)\n"
00050                         "                                       7=FlyCapture2 (Bumblebee2)\n"
00051                         "  --device #     Device id\n"
00052                         "  --debug        Debug log\n"
00053                         "  --stereo       Stereo: assuming device provides \n"
00054                         "                 side-by-side stereo images, otherwise \n"
00055                         "                 add also \"--device_r #\" for the right device.\n\n");
00056         exit(1);
00057 }
00058 
00059 int main(int argc, char * argv[])
00060 {
00061         ULogger::setType(ULogger::kTypeConsole);
00062         ULogger::setLevel(ULogger::kInfo);
00063         ULogger::setPrintTime(false);
00064         ULogger::setPrintWhere(false);
00065 
00066         int driver = -1;
00067         int device = 0;
00068         int deviceRight = -1;
00069         bool stereo = false;
00070         for(int i=1; i<argc; ++i)
00071         {
00072                 if(strcmp(argv[i], "--driver") == 0)
00073                 {
00074                         ++i;
00075                         if(i < argc)
00076                         {
00077                                 driver = std::atoi(argv[i]);
00078                                 if(driver < -1)
00079                                 {
00080                                         showUsage();
00081                                 }
00082                         }
00083                         else
00084                         {
00085                                 showUsage();
00086                         }
00087                         continue;
00088                 }
00089                 if(strcmp(argv[i], "--device") == 0)
00090                 {
00091                         ++i;
00092                         if(i < argc)
00093                         {
00094                                 device = std::atoi(argv[i]);
00095                                 if(device < 0)
00096                                 {
00097                                         showUsage();
00098                                 }
00099                         }
00100                         else
00101                         {
00102                                 showUsage();
00103                         }
00104                         continue;
00105                 }
00106                 if(strcmp(argv[i], "--device_r") == 0)
00107                 {
00108                         ++i;
00109                         if(i < argc)
00110                         {
00111                                 deviceRight = std::atoi(argv[i]);
00112                                 if(deviceRight < 0)
00113                                 {
00114                                         showUsage();
00115                                 }
00116                         }
00117                         else
00118                         {
00119                                 showUsage();
00120                         }
00121                         continue;
00122                 }
00123                 if(strcmp(argv[i], "--debug") == 0)
00124                 {
00125                         ULogger::setLevel(ULogger::kDebug);
00126                         ULogger::setPrintTime(true);
00127                         ULogger::setPrintWhere(true);
00128                         continue;
00129                 }
00130                 if(strcmp(argv[i], "--stereo") == 0)
00131                 {
00132                         stereo=true;
00133                         continue;
00134                 }
00135                 if(strcmp(argv[i], "--help") == 0)
00136                 {
00137                         showUsage();
00138                 }
00139                 printf("Unrecognized option : %s\n", argv[i]);
00140                 showUsage();
00141         }
00142         if(driver < -1 || driver > 7)
00143         {
00144                 UERROR("driver should be between -1 and 7.");
00145                 showUsage();
00146         }
00147 
00148         UINFO("Using driver %d", driver);
00149         UINFO("Using device %d", device);
00150         UINFO("Stereo: %s", stereo?"true":"false");
00151         if(stereo && deviceRight >= 0)
00152         {
00153                 UINFO("Using right device %d", deviceRight);
00154         }
00155 
00156         QApplication app(argc, argv);
00157         rtabmap::CalibrationDialog dialog(stereo, ".");
00158 
00159         rtabmap::Camera * camera = 0;
00160         if(driver == -1)
00161         {
00162                 if(stereo)
00163                 {
00164                         if(deviceRight>=0)
00165                         {
00166                                 // left and right videos
00167                                 camera = new rtabmap::CameraStereoVideo(device, deviceRight);
00168                         }
00169                         else
00170                         {
00171                                 // side-by-side video
00172                                 camera = new rtabmap::CameraStereoVideo(device);
00173                         }
00174                 }
00175                 else
00176                 {
00177                         camera = new rtabmap::CameraVideo(device);
00178                 }
00179                 dialog.setStereoMode(stereo);
00180         }
00181         else if(driver == 0)
00182         {
00183                 camera = new rtabmap::CameraOpenni();
00184         }
00185         else if(driver == 1)
00186         {
00187                 if(!rtabmap::CameraOpenNI2::available())
00188                 {
00189                         UERROR("Not built with OpenNI2 support...");
00190                         exit(-1);
00191                 }
00192                 camera = new rtabmap::CameraOpenNI2();
00193         }
00194         else if(driver == 2)
00195         {
00196                 if(!rtabmap::CameraFreenect::available())
00197                 {
00198                         UERROR("Not built with Freenect support...");
00199                         exit(-1);
00200                 }
00201                 camera = new rtabmap::CameraFreenect();
00202         }
00203         else if(driver == 3)
00204         {
00205                 if(!rtabmap::CameraOpenNICV::available())
00206                 {
00207                         UERROR("Not built with OpenNI from OpenCV support...");
00208                         exit(-1);
00209                 }
00210                 camera = new rtabmap::CameraOpenNICV(false);
00211         }
00212         else if(driver == 4)
00213         {
00214                 if(!rtabmap::CameraOpenNICV::available())
00215                 {
00216                         UERROR("Not built with OpenNI from OpenCV support...");
00217                         exit(-1);
00218                 }
00219                 camera = new rtabmap::CameraOpenNICV(true);
00220         }
00221         else if(driver == 5)
00222         {
00223                 if(!rtabmap::CameraFreenect2::available())
00224                 {
00225                         UERROR("Not built with Freenect2 support...");
00226                         exit(-1);
00227                 }
00228                 camera = new rtabmap::CameraFreenect2(0, rtabmap::CameraFreenect2::kTypeColorIR);
00229                 dialog.setSwitchedImages(true);
00230                 dialog.setStereoMode(stereo, "rgb", "depth");
00231         }
00232         else if(driver == 6)
00233         {
00234                 if(!rtabmap::CameraStereoDC1394::available())
00235                 {
00236                         UERROR("Not built with DC1394 support...");
00237                         exit(-1);
00238                 }
00239                 camera = new rtabmap::CameraStereoDC1394();
00240                 dialog.setStereoMode(stereo);
00241         }
00242         else if(driver == 7)
00243         {
00244                 if(!rtabmap::CameraStereoFlyCapture2::available())
00245                 {
00246                         UERROR("Not built with FlyCapture2/Triclops support...");
00247                         exit(-1);
00248                 }
00249                 camera = new rtabmap::CameraStereoFlyCapture2();
00250                 dialog.setStereoMode(stereo);
00251         }
00252         else
00253         {
00254                 UFATAL("");
00255         }
00256 
00257         rtabmap::CameraThread * cameraThread = 0;
00258 
00259         if(camera)
00260         {
00261                 if(!camera->init(""))
00262                 {
00263                         printf("Camera init failed!\n");
00264                         delete camera;
00265                         exit(1);
00266                 }
00267                 cameraThread = new rtabmap::CameraThread(camera);
00268         }
00269 
00270         dialog.registerToEventsManager();
00271 
00272         dialog.show();
00273         cameraThread->start();
00274         app.exec();
00275         cameraThread->join(true);
00276         delete cameraThread;
00277 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:20