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


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