Skip to content

Commit 94bd360

Browse files
authored
rtabmap-matcher: Added option to recfify raw images for convenience (#1663)
1 parent f94a963 commit 94bd360

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

tools/Matcher/main.cpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void showUsage()
8787
" --to_depth \"to_depth.png\" Depth or right image file of the second image.\n"
8888
" For 3D->3D estimation, from_depth and to_depth\n"
8989
" should be both set.\n"
90+
" --raw Provided images are raw and should be rectified.\n"
91+
" Doesn't need to be explicitly set if calibration\n"
92+
" is not provided. For RGB-D data, only the RGB image\n"
93+
" is rectified, the depth is assumed already matching\n"
94+
" the rectified one.\n"
9095
"\n\n"
9196
"%s\n",
9297
Parameters::showUsage());
@@ -107,6 +112,7 @@ int main(int argc, char * argv[])
107112
std::string toDepthPath;
108113
std::string calibrationPath;
109114
std::string calibrationToPath;
115+
bool imagesRectified = true;
110116
for(int i=1; i<argc-2; ++i)
111117
{
112118
if(strcmp(argv[i], "--from_depth") == 0)
@@ -157,6 +163,10 @@ int main(int argc, char * argv[])
157163
showUsage();
158164
}
159165
}
166+
else if(strcmp(argv[i], "--raw") == 0)
167+
{
168+
imagesRectified = false;
169+
}
160170
else if(strcmp(argv[i], "--help") == 0)
161171
{
162172
showUsage();
@@ -171,6 +181,10 @@ int main(int argc, char * argv[])
171181
}
172182
printf(" --from_depth = \"%s\"\n", fromDepthPath.c_str());
173183
printf(" --to_depth = \"%s\"\n", toDepthPath.c_str());
184+
if(!imagesRectified)
185+
{
186+
printf(" --raw (images will be rectified)\n");
187+
}
174188

175189
#ifdef RTABMAP_PYTHON
176190
rtabmap::PythonInterface pythonInterface;
@@ -311,12 +325,57 @@ int main(int argc, char * argv[])
311325
if(model.isValidForProjection())
312326
{
313327
printf("Mono calibration model detected.\n");
328+
329+
if(!imagesRectified)
330+
{
331+
if(!model.isValidForRectification())
332+
{
333+
printf("ERROR: calibration model \"%s\" is not valid for rectification and --raw option was set. Aborting.\n", calibrationPath.c_str());
334+
exit(-1);
335+
}
336+
if(!model.isRectificationMapInitialized()) {
337+
model.initRectificationMap();
338+
}
339+
if(!modelTo.isValidForRectification())
340+
{
341+
printf("ERROR: calibration model \"%s\" is not valid for rectification and --raw option was set. Aborting.\n", calibrationToPath.c_str());
342+
exit(-1);
343+
}
344+
if(!modelTo.isRectificationMapInitialized()) {
345+
modelTo.initRectificationMap();
346+
}
347+
imageFrom = model.rectifyImage(imageFrom);
348+
imageTo = modelTo.rectifyImage(imageTo);
349+
}
314350
dataFrom = SensorData(imageFrom, fromDepth, model, 1);
315351
dataTo = SensorData(imageTo, toDepth, modelTo, 2);
316352
}
317353
else //stereo
318354
{
319355
printf("Stereo calibration model detected.\n");
356+
if(!imagesRectified)
357+
{
358+
if(!stereoModel.isValidForRectification())
359+
{
360+
printf("ERROR: stereo calibration model \"%s\" is not valid for rectification and --raw option was set. Aborting.\n", calibrationPath.c_str());
361+
exit(-1);
362+
}
363+
if(!stereoModel.isRectificationMapInitialized()) {
364+
stereoModel.initRectificationMap();
365+
}
366+
if(!stereoModelTo.isValidForRectification())
367+
{
368+
printf("ERROR: stereo calibration model \"%s\" is not valid for rectification and --raw option was set. Aborting.\n", calibrationToPath.c_str());
369+
exit(-1);
370+
}
371+
if(!stereoModelTo.isRectificationMapInitialized()) {
372+
stereoModelTo.initRectificationMap();
373+
}
374+
imageFrom = stereoModel.left().rectifyImage(imageFrom);
375+
fromDepth = stereoModel.right().rectifyImage(fromDepth);
376+
imageTo = stereoModelTo.left().rectifyImage(imageTo);
377+
toDepth = stereoModelTo.right().rectifyImage(toDepth);
378+
}
320379
dataFrom = SensorData(imageFrom, fromDepth, stereoModel, 1);
321380
dataTo = SensorData(imageTo, toDepth, stereoModelTo, 2);
322381
}
@@ -329,7 +388,7 @@ int main(int argc, char * argv[])
329388
{
330389
parameters.insert(ParametersPair(Parameters::kVisEstimationType(), "2")); // Set 2D->2D estimation for mono images
331390
parameters.insert(ParametersPair(Parameters::kVisEpipolarGeometryVar(), "1")); //Unknown scale
332-
printf("Calibration not set, setting %s=1 and %s=2 by default (2D->2D estimation)\n", Parameters::kVisEpipolarGeometryVar().c_str(), Parameters::kVisEstimationType().c_str());
391+
printf("Depth/Stereo not set, setting %s=1 and %s=2 by default (2D->2D estimation)\n", Parameters::kVisEpipolarGeometryVar().c_str(), Parameters::kVisEstimationType().c_str());
333392
}
334393
RegistrationVis reg(parameters);
335394
RegistrationInfo info;

0 commit comments

Comments
 (0)