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