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/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);
00181 while(!rgb.empty())
00182 {
00183 cv::imshow("Video", rgb);
00184
00185 int c = cv::waitKey(10);
00186 if(c == 27)
00187 break;
00188
00189 rgb = camera->takeImage().imageRaw();
00190 }
00191 cv::destroyWindow("Video");
00192 if(camera)
00193 {
00194 delete camera;
00195 }
00196 return 0;
00197 }