tools/Camera/main.cpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #include "rtabmap/core/CameraRGB.h"
29 #include "rtabmap/core/DBReader.h"
31 #include "rtabmap/utilite/UFile.h"
34 #include <opencv2/highgui/highgui.hpp>
35 #include <opencv2/highgui/highgui_c.h>
36 #include <stdio.h>
37 
38 void showUsage()
39 {
40  printf("\nUsage:\n"
41  "rtabmap-camera [option] \n"
42  " Options:\n"
43  " --device # USB camera device id (default 0).\n"
44  " --rate # Frame rate (default 0 Hz). 0 means as fast as possible.\n"
45  " --path "" Path to a directory of images or a video file.\n"
46  " --calibration "" Calibration file (*.yaml).\n\n");
47  exit(1);
48 }
49 
50 int main(int argc, char * argv[])
51 {
54 
55  int device = 0;
56  std::string path;
57  float rate = 0.0f;
58  std::string calibrationFile;
59  for(int i=1; i<argc; ++i)
60  {
61  if(strcmp(argv[i], "--rate") == 0)
62  {
63  ++i;
64  if(i < argc)
65  {
66  rate = uStr2Float(argv[i]);
67  if(rate < 0)
68  {
69  showUsage();
70  }
71  }
72  else
73  {
74  showUsage();
75  }
76  continue;
77  }
78  if(strcmp(argv[i], "--device") == 0)
79  {
80  ++i;
81  if(i < argc)
82  {
83  device = std::atoi(argv[i]);
84  if(device < 0)
85  {
86  showUsage();
87  }
88  }
89  else
90  {
91  showUsage();
92  }
93  continue;
94  }
95  if(strcmp(argv[i], "--path") == 0)
96  {
97  ++i;
98  if(i < argc)
99  {
100  path = argv[i];
101  }
102  else
103  {
104  showUsage();
105  }
106  continue;
107  }
108  if(strcmp(argv[i], "--calibration") == 0)
109  {
110  ++i;
111  if(i < argc)
112  {
113  calibrationFile = argv[i];
114  }
115  else
116  {
117  showUsage();
118  }
119  continue;
120  }
121 
122  printf("Unrecognized option : %s\n", argv[i]);
123  showUsage();
124  }
125 
126  if(path.empty())
127  {
128  UINFO("Using device %d", device);
129  }
130  else
131  {
132  UINFO("Using path %s", path.c_str());
133  }
134 
135  rtabmap::Camera * camera = 0;
136 
137  if(!path.empty())
138  {
139  if(UFile::exists(path))
140  {
141  if(UFile::getExtension(path).compare("db") == 0)
142  {
143  camera = new rtabmap::DBReader(path, rate);
144  }
145  else
146  {
147  camera = new rtabmap::CameraVideo(path, false, rate);
148  }
149  }
150  else if(UDirectory::exists(path))
151  {
152  camera = new rtabmap::CameraImages(path, rate);
153  }
154  else
155  {
156  UERROR("Path not valid! \"%s\"", path.c_str());
157  return -1;
158  }
159  }
160  else
161  {
162  camera = new rtabmap::CameraVideo(device, false, rate);
163  }
164 
165  if(camera)
166  {
167  if(!calibrationFile.empty())
168  {
169  UINFO("Set calibration: %s", calibrationFile.c_str());
170  }
171  if(!camera->init(UDirectory::getDir(calibrationFile), UFile::getName(calibrationFile)))
172  {
173  delete camera;
174  UERROR("Cannot initialize the camera.");
175  return -1;
176  }
177  }
178 
179  cv::Mat rgb;
180  rgb = camera->takeImage().imageRaw();
181  cv::namedWindow("Video", CV_WINDOW_AUTOSIZE); // create window
182  while(!rgb.empty())
183  {
184  cv::imshow("Video", rgb); // show frame
185 
186  int c = cv::waitKey(10); // wait 10 ms or for key stroke
187  if(c == 27)
188  break; // if ESC, break and quit
189 
190  rgb = camera->takeImage().imageRaw();
191  }
192  cv::destroyWindow("Video");
193  if(camera)
194  {
195  delete camera;
196  }
197  return 0;
198 }
compare
bool compare
UFile::getName
std::string getName()
Definition: UFile.h:135
rtabmap::CameraImages
Definition: CameraImages.h:39
UINFO
#define UINFO(...)
showUsage
void showUsage()
Definition: tools/Camera/main.cpp:38
c
Scalar Scalar * c
UDirectory.h
ULogger::kTypeConsole
@ kTypeConsole
Definition: ULogger.h:244
ULogger::setLevel
static void setLevel(ULogger::Level level)
Definition: ULogger.h:339
DBReader.h
UDirectory::getDir
static std::string getDir(const std::string &filePath)
Definition: UDirectory.cpp:273
UConversion.h
Some conversion functions.
UFile::getExtension
std::string getExtension()
Definition: UFile.h:140
rtabmap_superglue.device
string device
Definition: rtabmap_superglue.py:21
ULogger::kInfo
@ kInfo
Definition: ULogger.h:252
rtabmap_netvlad.argv
argv
Definition: rtabmap_netvlad.py:15
main
int main(int argc, char *argv[])
Definition: tools/Camera/main.cpp:50
ULogger::setType
static void setType(Type type, const std::string &fileName=kDefaultLogFileName, bool append=true)
Definition: ULogger.cpp:176
CameraRGB.h
rtabmap::Camera
Definition: Camera.h:43
path
path
ULogger.h
ULogger class and convenient macros.
UDirectory::exists
static bool exists(const std::string &dirPath)
Definition: UDirectory.cpp:249
camera
Camera camera(Pose3(Rot3().retract(Vector3(0.1, 0.2, 0.3)), Point3(0, 5, 0)), Cal3Bundler0(1, 0, 0))
rtabmap::DBReader
Definition: DBReader.h:46
uStr2Float
float UTILITE_EXPORT uStr2Float(const std::string &str)
Definition: UConversion.cpp:138
UFile.h
UFile::exists
bool exists()
Definition: UFile.h:104
UERROR
#define UERROR(...)
i
int i
rtabmap::CameraVideo
Definition: CameraVideo.h:36


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:12