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/utilite/ULogger.h>
00029 #include <rtabmap/utilite/UFile.h>
00030 #include <rtabmap/utilite/UConversion.h>
00031 #include <rtabmap/core/CameraThread.h>
00032 #include <rtabmap/core/CameraRGBD.h>
00033 #include <rtabmap/core/CameraStereo.h>
00034 #include <rtabmap/core/Camera.h>
00035 #include <rtabmap/core/CameraThread.h>
00036 #include <rtabmap/gui/DataRecorder.h>
00037 #include <QApplication>
00038 #include <signal.h>
00039 
00040 using namespace rtabmap;
00041 
00042 void showUsage()
00043 {
00044         printf("\nUsage:\n"
00045                         "dataRecorder [options] output.db\n"
00046                         "Options:\n"
00047                         "  -hide                    Don't display the current cloud recorded.\n"
00048                         "  -debug                   Set debug level for the logger.\n"
00049                         "  -rate #.#                Input rate Hz (default 0=inf)\n"
00050                         "  -driver                  Driver number to use:\n"
00051                         "                                     0=OpenNI-PCL (Kinect)\n"
00052                         "                                     1=OpenNI2    (Kinect and Xtion PRO Live)\n"
00053                         "                                     2=Freenect   (Kinect)\n"
00054                         "                                     3=OpenNI-CV  (Kinect)\n"
00055                         "                                     4=OpenNI-CV-ASUS (Xtion PRO Live)\n"
00056                         "                                     5=Freenect2  (Kinect v2)\n"
00057                         "                                     6=DC1394     (Bumblebee2)\n"
00058                         "                                     7=FlyCapture2 (Bumblebee2)\n"
00059                         "  -device ""                Device ID (default \"\")\n");
00060         exit(1);
00061 }
00062 
00063 rtabmap::CameraThread * cam = 0;
00064 QApplication * app = 0;
00065 // catch ctrl-c
00066 void sighandler(int sig)
00067 {
00068         printf("\nSignal %d caught...\n", sig);
00069         if(cam)
00070         {
00071                 cam->join(true);
00072         }
00073         if(app)
00074         {
00075                 QMetaObject::invokeMethod(app, "quit");
00076         }
00077 }
00078 
00079 int main (int argc, char * argv[])
00080 {
00081         ULogger::setType(ULogger::kTypeConsole);
00082         ULogger::setLevel(ULogger::kInfo);
00083 
00084         // parse arguments
00085         QString fileName;
00086         bool show = true;
00087         int driver = 0;
00088         std::string deviceId;
00089         float rate = 0.0f;
00090 
00091         if(argc < 2)
00092         {
00093                 showUsage();
00094         }
00095         for(int i=1; i<argc-1; ++i)
00096         {
00097                 if(strcmp(argv[i], "-rate") == 0)
00098                 {
00099                         ++i;
00100                         if(i < argc)
00101                         {
00102                                 rate = uStr2Float(argv[i]);
00103                                 if(rate < 0.0f)
00104                                 {
00105                                         showUsage();
00106                                 }
00107                         }
00108                         else
00109                         {
00110                                 showUsage();
00111                         }
00112                         continue;
00113                 }
00114                 if(strcmp(argv[i], "-debug") == 0)
00115                 {
00116                         ULogger::setLevel(ULogger::kDebug);
00117                         continue;
00118                 }
00119                 if(strcmp(argv[i], "-hide") == 0)
00120                 {
00121                         show = false;
00122                         continue;
00123                 }
00124                 if(strcmp(argv[i], "-driver") == 0)
00125                 {
00126                         ++i;
00127                         if(i < argc)
00128                         {
00129                                 driver = std::atoi(argv[i]);
00130                                 if(driver < 0 || driver > 7)
00131                                 {
00132                                         showUsage();
00133                                 }
00134                         }
00135                         else
00136                         {
00137                                 showUsage();
00138                         }
00139                         continue;
00140                 }
00141                 if(strcmp(argv[i], "-device") == 0)
00142                 {
00143                         ++i;
00144                         if(i < argc)
00145                         {
00146                                 deviceId = argv[i];
00147                         }
00148                         else
00149                         {
00150                                 showUsage();
00151                         }
00152                         continue;
00153                 }
00154 
00155                 printf("Unrecognized option : %s\n", argv[i]);
00156                 showUsage();
00157         }
00158         fileName = argv[argc-1]; // the last is the output path
00159 
00160         if(UFile::getExtension(fileName.toStdString()).compare("db") != 0)
00161         {
00162                 printf("Database names must end with .db extension\n");
00163                 showUsage();
00164         }
00165 
00166         UINFO("Output = %s", fileName.toStdString().c_str());
00167         UINFO("Show = %s", show?"true":"false");
00168         UINFO("Rate =%f Hz", rate);
00169 
00170         app = new QApplication(argc, argv);
00171 
00172         // Catch ctrl-c to close the gui
00173         // (Place this after QApplication's constructor)
00174         signal(SIGABRT, &sighandler);
00175         signal(SIGTERM, &sighandler);
00176         signal(SIGINT, &sighandler);
00177 
00178         rtabmap::Camera * camera = 0;
00179         rtabmap::Transform t=rtabmap::Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0);
00180         if(driver == 0)
00181         {
00182                 camera = new rtabmap::CameraOpenni(deviceId, rate, t);
00183         }
00184         else if(driver == 1)
00185         {
00186                 if(!rtabmap::CameraOpenNI2::available())
00187                 {
00188                         UERROR("Not built with OpenNI2 support...");
00189                         exit(-1);
00190                 }
00191                 camera = new rtabmap::CameraOpenNI2(deviceId, CameraOpenNI2::kTypeColorDepth, rate, t);
00192         }
00193         else if(driver == 2)
00194         {
00195                 if(!rtabmap::CameraFreenect::available())
00196                 {
00197                         UERROR("Not built with Freenect support...");
00198                         exit(-1);
00199                 }
00200                 camera = new rtabmap::CameraFreenect(deviceId.size()?atoi(deviceId.c_str()):0, CameraFreenect::kTypeColorDepth, rate, t);
00201         }
00202         else if(driver == 3)
00203         {
00204                 if(!rtabmap::CameraOpenNICV::available())
00205                 {
00206                         UERROR("Not built with OpenNI from OpenCV support...");
00207                         exit(-1);
00208                 }
00209                 camera = new rtabmap::CameraOpenNICV(false, rate, t);
00210         }
00211         else if(driver == 4)
00212         {
00213                 if(!rtabmap::CameraOpenNICV::available())
00214                 {
00215                         UERROR("Not built with OpenNI from OpenCV support...");
00216                         exit(-1);
00217                 }
00218                 camera = new rtabmap::CameraOpenNICV(true, rate, t);
00219         }
00220         else if(driver == 5)
00221         {
00222                 if(!rtabmap::CameraFreenect2::available())
00223                 {
00224                         UERROR("Not built with Freenect2 support...");
00225                         exit(-1);
00226                 }
00227                 camera = new rtabmap::CameraFreenect2(deviceId.size()?atoi(deviceId.c_str()):0, rtabmap::CameraFreenect2::kTypeColor2DepthSD, rate, t);
00228         }
00229         else if(driver == 6)
00230         {
00231                 if(!rtabmap::CameraStereoDC1394::available())
00232                 {
00233                         UERROR("Not built with dc1394 support...");
00234                         exit(-1);
00235                 }
00236                 camera = new rtabmap::CameraStereoDC1394(rate, t);
00237         }
00238         else if(driver == 7)
00239         {
00240                 if(!rtabmap::CameraStereoFlyCapture2::available())
00241                 {
00242                         UERROR("Not built with FlyCapture2/Triclops support...");
00243                         exit(-1);
00244                 }
00245                 camera = new rtabmap::CameraStereoFlyCapture2(rate, t);
00246         }
00247         else
00248         {
00249                 UFATAL("Camera driver (%d) not found!", driver);
00250         }
00251         cam = new CameraThread(camera);
00252 
00253         DataRecorder recorder;
00254 
00255         if(recorder.init(fileName))
00256         {
00257                 recorder.registerToEventsManager();
00258                 if(show)
00259                 {
00260                         recorder.setWindowTitle("Data recorder");
00261                         recorder.setMinimumWidth(500);
00262                         recorder.setMinimumHeight(300);
00263                         recorder.showNormal();
00264                         app->processEvents();
00265                 }
00266 
00267                 if(camera->init())
00268                 {
00269                         cam->start();
00270 
00271                         app->exec();
00272 
00273                         UINFO("Closing...");
00274 
00275                         recorder.close();
00276                 }
00277                 else
00278                 {
00279                         UERROR("Cannot initialize the camera!");
00280                 }
00281         }
00282         else
00283         {
00284                 UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.toStdString().c_str());
00285         }
00286 
00287         if(cam)
00288         {
00289                 delete cam;
00290         }
00291 
00292         return 0;
00293 }


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