Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "rtabmap/core/Camera.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 30 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 = 30.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 rtabmap::DBReader * dbReader = 0;
00136
00137 if(!path.empty())
00138 {
00139 if(UFile::exists(path))
00140 {
00141 if(UFile::getExtension(path).compare("db") == 0)
00142 {
00143 dbReader = new rtabmap::DBReader(path, rate);
00144 }
00145 else
00146 {
00147 camera = new rtabmap::CameraVideo(path, rate);
00148 }
00149 }
00150 else if(UDirectory::exists(path))
00151 {
00152 camera = new rtabmap::CameraImages(path, rate);
00153 }
00154 else
00155 {
00156 UERROR("Path not valid! \"%s\"", path.c_str());
00157 return -1;
00158 }
00159 }
00160 else
00161 {
00162 camera = new rtabmap::CameraVideo(device, rate);
00163 }
00164
00165 if(camera)
00166 {
00167 if(!camera->init())
00168 {
00169 delete camera;
00170 UERROR("Cannot initialize the camera.");
00171 return -1;
00172 }
00173
00174 if(!calibrationFile.empty())
00175 {
00176 UINFO("Set calibration: %s", calibrationFile.c_str());
00177 camera->setCalibration(calibrationFile);
00178 }
00179 }
00180
00181 if(dbReader)
00182 {
00183 if(!dbReader->init())
00184 {
00185 delete dbReader;
00186 UERROR("Cannot initialize the camera.");
00187 return -1;
00188 }
00189 }
00190
00191 cv::Mat rgb;
00192 rgb = camera?camera->takeImage():dbReader->getNextData().image();
00193 cv::namedWindow("Video", CV_WINDOW_AUTOSIZE);
00194 while(!rgb.empty())
00195 {
00196 cv::imshow("Video", rgb);
00197
00198 int c = cv::waitKey(10);
00199 if(c == 27)
00200 break;
00201
00202 rgb = camera?camera->takeImage():dbReader->getNextData().image();
00203 }
00204 cv::destroyWindow("Video");
00205 if(camera)
00206 {
00207 delete camera;
00208 }
00209 if(dbReader)
00210 {
00211 delete dbReader;
00212 }
00213 return 0;
00214 }