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/DBReader.h"
00030 #include "rtabmap/utilite/ULogger.h"
00031 #include "rtabmap/utilite/UFile.h"
00032 #include "rtabmap/utilite/UDirectory.h"
00033 #include "rtabmap/utilite/UConversion.h"
00034 #include <opencv2/highgui/highgui.hpp>
00035 #include <stdio.h>
00036 
00037 void showUsage()
00038 {
00039         printf("\nUsage:\n"
00040                         "rtabmap-camera [option] \n"
00041                         " Options:\n"
00042                         "    --device #            USB camera device id (default 0).\n"
00043                         "    --rate #              Frame rate (default 0 Hz). 0 means as fast as possible.\n"
00044                         "    --path ""             Path to a directory of images or a video file.\n"
00045                         "    --calibration ""      Calibration file (*.yaml).\n\n");
00046         exit(1);
00047 }
00048 
00049 int main(int argc, char * argv[])
00050 {
00051         ULogger::setType(ULogger::kTypeConsole);
00052         ULogger::setLevel(ULogger::kInfo);
00053 
00054         int device = 0;
00055         std::string path;
00056         float rate = 0.0f;
00057         std::string calibrationFile;
00058         for(int i=1; i<argc; ++i)
00059         {
00060                 if(strcmp(argv[i], "--rate") == 0)
00061                 {
00062                         ++i;
00063                         if(i < argc)
00064                         {
00065                                 rate = uStr2Float(argv[i]);
00066                                 if(rate < 0)
00067                                 {
00068                                         showUsage();
00069                                 }
00070                         }
00071                         else
00072                         {
00073                                 showUsage();
00074                         }
00075                         continue;
00076                 }
00077                 if(strcmp(argv[i], "--device") == 0)
00078                 {
00079                         ++i;
00080                         if(i < argc)
00081                         {
00082                                 device = std::atoi(argv[i]);
00083                                 if(device < 0)
00084                                 {
00085                                         showUsage();
00086                                 }
00087                         }
00088                         else
00089                         {
00090                                 showUsage();
00091                         }
00092                         continue;
00093                 }
00094                 if(strcmp(argv[i], "--path") == 0)
00095                 {
00096                         ++i;
00097                         if(i < argc)
00098                         {
00099                                 path = argv[i];
00100                         }
00101                         else
00102                         {
00103                                 showUsage();
00104                         }
00105                         continue;
00106                 }
00107                 if(strcmp(argv[i], "--calibration") == 0)
00108                 {
00109                         ++i;
00110                         if(i < argc)
00111                         {
00112                                 calibrationFile = argv[i];
00113                         }
00114                         else
00115                         {
00116                                 showUsage();
00117                         }
00118                         continue;
00119                 }
00120 
00121                 printf("Unrecognized option : %s\n", argv[i]);
00122                 showUsage();
00123         }
00124 
00125         if(path.empty())
00126         {
00127                 UINFO("Using device %d", device);
00128         }
00129         else
00130         {
00131                 UINFO("Using path %s", path.c_str());
00132         }
00133 
00134         rtabmap::Camera * camera = 0;
00135 
00136         if(!path.empty())
00137         {
00138                 if(UFile::exists(path))
00139                 {
00140                         if(UFile::getExtension(path).compare("db") == 0)
00141                         {
00142                                 camera = new rtabmap::DBReader(path, rate);
00143                         }
00144                         else
00145                         {
00146                                 camera = new rtabmap::CameraVideo(path, false, rate);
00147                         }
00148                 }
00149                 else if(UDirectory::exists(path))
00150                 {
00151                         camera = new rtabmap::CameraImages(path, rate);
00152                 }
00153                 else
00154                 {
00155                         UERROR("Path not valid! \"%s\"", path.c_str());
00156                         return -1;
00157                 }
00158         }
00159         else
00160         {
00161                 camera = new rtabmap::CameraVideo(device, rate);
00162         }
00163 
00164         if(camera)
00165         {
00166                 if(!calibrationFile.empty())
00167                 {
00168                         UINFO("Set calibration: %s", calibrationFile.c_str());
00169                 }
00170                 if(!camera->init(UDirectory::getDir(calibrationFile), UFile::getName(calibrationFile)))
00171                 {
00172                         delete camera;
00173                         UERROR("Cannot initialize the camera.");
00174                         return -1;
00175                 }
00176         }
00177 
00178         cv::Mat rgb;
00179         rgb = camera->takeImage().imageRaw();
00180         cv::namedWindow("Video", CV_WINDOW_AUTOSIZE); // create window
00181         while(!rgb.empty())
00182         {
00183                 cv::imshow("Video", rgb); // show frame
00184 
00185                 int c = cv::waitKey(10); // wait 10 ms or for key stroke
00186                 if(c == 27)
00187                         break; // if ESC, break and quit
00188 
00189                 rgb = camera->takeImage().imageRaw();
00190         }
00191         cv::destroyWindow("Video");
00192         if(camera)
00193         {
00194                 delete camera;
00195         }
00196         return 0;
00197 }


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sat Jul 23 2016 11:44:16