main.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2014, 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/Camera.h"
00029 #include "rtabmap/core/CameraRGBD.h"
00030 #include "rtabmap/core/CameraThread.h"
00031 #include "rtabmap/utilite/ULogger.h"
00032 #include "rtabmap/utilite/UConversion.h"
00033 #include "rtabmap/gui/CalibrationDialog.h"
00034 #include <QApplication>
00035 
00036 void showUsage()
00037 {
00038         printf("\nUsage:\n"
00039                         "rtabmap-calibration [options]\n"
00040                         "Options:\n"
00041                         "  --driver #     Driver number to use:-1=USB camera\n"
00042                         "                                       0=OpenNI-PCL (Kinect)\n"
00043                         "                                       1=OpenNI2    (Kinect and Xtion PRO Live)\n"
00044                         "                                       2=Freenect   (Kinect)\n"
00045                         "                                       3=OpenNI-CV  (Kinect)\n"
00046                         "                                       4=OpenNI-CV-ASUS (Xtion PRO Live)\n"
00047                         "                                       5=Freenect2  (Kinect v2)\n"
00048                         "                                       6=DC1394     (Bumblebee2)\n"
00049                         "                                       7=FlyCapture2 (Bumblebee2)\n"
00050                         "  --device #     Device id\n"
00051                         "  --debug        Debug log\n"
00052                         "  --stereo       Stereo\n\n");
00053         exit(1);
00054 }
00055 
00056 int main(int argc, char * argv[])
00057 {
00058         ULogger::setType(ULogger::kTypeConsole);
00059         ULogger::setLevel(ULogger::kInfo);
00060         ULogger::setPrintTime(false);
00061         ULogger::setPrintWhere(false);
00062 
00063         int driver = -1;
00064         int device = 0;
00065         bool stereo = false;
00066         for(int i=1; i<argc; ++i)
00067         {
00068                 if(strcmp(argv[i], "--driver") == 0)
00069                 {
00070                         ++i;
00071                         if(i < argc)
00072                         {
00073                                 driver = std::atoi(argv[i]);
00074                                 if(driver < -1)
00075                                 {
00076                                         showUsage();
00077                                 }
00078                         }
00079                         else
00080                         {
00081                                 showUsage();
00082                         }
00083                         continue;
00084                 }
00085                 if(strcmp(argv[i], "--device") == 0)
00086                 {
00087                         ++i;
00088                         if(i < argc)
00089                         {
00090                                 device = std::atoi(argv[i]);
00091                                 if(device < 0)
00092                                 {
00093                                         showUsage();
00094                                 }
00095                         }
00096                         else
00097                         {
00098                                 showUsage();
00099                         }
00100                         continue;
00101                 }
00102                 if(strcmp(argv[i], "--debug") == 0)
00103                 {
00104                         ULogger::setLevel(ULogger::kDebug);
00105                         ULogger::setPrintTime(true);
00106                         ULogger::setPrintWhere(true);
00107                         continue;
00108                 }
00109                 if(strcmp(argv[i], "--stereo") == 0)
00110                 {
00111                         stereo=true;
00112                         continue;
00113                 }
00114                 if(strcmp(argv[i], "--help") == 0)
00115                 {
00116                         showUsage();
00117                 }
00118                 printf("Unrecognized option : %s\n", argv[i]);
00119                 showUsage();
00120         }
00121         if(driver < -1 || driver > 7)
00122         {
00123                 UERROR("driver should be between -1 and 7.");
00124                 showUsage();
00125         }
00126 
00127         UINFO("Using driver %d", driver);
00128         UINFO("Using device %d", device);
00129         UINFO("Stereo: %s", stereo?"true":"false");
00130 
00131         bool switchImages = false;
00132 
00133         rtabmap::Camera * cameraUsb = 0;
00134         rtabmap::CameraRGBD * camera = 0;
00135         if(driver == -1)
00136         {
00137                 cameraUsb = new rtabmap::CameraVideo(device);
00138         }
00139         else if(driver == 0)
00140         {
00141                 camera = new rtabmap::CameraOpenni();
00142         }
00143         else if(driver == 1)
00144         {
00145                 if(!rtabmap::CameraOpenNI2::available())
00146                 {
00147                         UERROR("Not built with OpenNI2 support...");
00148                         exit(-1);
00149                 }
00150                 camera = new rtabmap::CameraOpenNI2();
00151         }
00152         else if(driver == 2)
00153         {
00154                 if(!rtabmap::CameraFreenect::available())
00155                 {
00156                         UERROR("Not built with Freenect support...");
00157                         exit(-1);
00158                 }
00159                 camera = new rtabmap::CameraFreenect();
00160         }
00161         else if(driver == 3)
00162         {
00163                 if(!rtabmap::CameraOpenNICV::available())
00164                 {
00165                         UERROR("Not built with OpenNI from OpenCV support...");
00166                         exit(-1);
00167                 }
00168                 camera = new rtabmap::CameraOpenNICV(false);
00169         }
00170         else if(driver == 4)
00171         {
00172                 if(!rtabmap::CameraOpenNICV::available())
00173                 {
00174                         UERROR("Not built with OpenNI from OpenCV support...");
00175                         exit(-1);
00176                 }
00177                 camera = new rtabmap::CameraOpenNICV(true);
00178         }
00179         else if(driver == 5)
00180         {
00181                 if(!rtabmap::CameraFreenect2::available())
00182                 {
00183                         UERROR("Not built with Freenect2 support...");
00184                         exit(-1);
00185                 }
00186                 switchImages = true;
00187                 camera = new rtabmap::CameraFreenect2(0, rtabmap::CameraFreenect2::kTypeRGBIR);
00188         }
00189         else if(driver == 6)
00190         {
00191                 if(!rtabmap::CameraStereoDC1394::available())
00192                 {
00193                         UERROR("Not built with DC1394 support...");
00194                         exit(-1);
00195                 }
00196                 camera = new rtabmap::CameraStereoDC1394();
00197         }
00198         else if(driver == 7)
00199         {
00200                 if(!rtabmap::CameraStereoFlyCapture2::available())
00201                 {
00202                         UERROR("Not built with FlyCapture2/Triclops support...");
00203                         exit(-1);
00204                 }
00205                 camera = new rtabmap::CameraStereoFlyCapture2();
00206         }
00207         else
00208         {
00209                 UFATAL("");
00210         }
00211 
00212         rtabmap::CameraThread * cameraThread = 0;
00213 
00214         if(cameraUsb)
00215         {
00216                 if(!cameraUsb->init())
00217                 {
00218                         printf("Camera init failed!\n");
00219                         delete cameraUsb;
00220                         exit(1);
00221                 }
00222                 cameraThread = new rtabmap::CameraThread(cameraUsb);
00223         }
00224         else if(camera)
00225         {
00226                 if(!camera->init(""))
00227                 {
00228                         printf("Camera init failed!\n");
00229                         delete camera;
00230                         exit(1);
00231                 }
00232                 cameraThread = new rtabmap::CameraThread(camera);
00233         }
00234 
00235         QApplication app(argc, argv);
00236         rtabmap::CalibrationDialog dialog(stereo, ".", switchImages);
00237         dialog.registerToEventsManager();
00238 
00239         dialog.show();
00240         cameraThread->start();
00241         app.exec();
00242         cameraThread->join(true);
00243         delete cameraThread;
00244 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Fri Aug 28 2015 12:51:31