MRPT  2.0.3
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
12 #include <mrpt/system/filesystem.h> // for ASSERT_FILE_EXISTS_
14 #include <iostream>
15 
16 using namespace mrpt;
17 using namespace mrpt::gui;
18 using namespace mrpt::vision;
19 using namespace mrpt::opengl;
20 using namespace mrpt::system;
21 using namespace mrpt::vision;
22 using namespace std;
23 
24 // ------------------------------------------------------
25 // TestStereoCalibrate
26 // ------------------------------------------------------
27 int TestStereoCalibrate(int argc, char** argv)
28 {
29  CTimeLogger timlog;
30 
31  // Parse optional arguments:
32  if (argc == 1 || ((argc - 1) & 1) != 0)
33  {
34  cout << "Usage:\n"
35  << argv[0] << "left_image1 right_image1 [L2 R2] [L3 R3] [...]\n";
36  return -1;
37  }
38 
39  // The stereo calibration structures:
40  TCalibrationStereoImageList calib_imgs;
41  TStereoCalibResults calib_result;
42  TStereoCalibParams calib_params;
43 
44  // ============ Set parameters ============
45  calib_params.check_size_x = 7;
46  calib_params.check_size_y = 9;
47  calib_params.check_squares_length_X_meters = 22.83e-3;
48  calib_params.check_squares_length_Y_meters = 24.31e-3;
49  // calib_params.maxIters = 300;
50  // calib_params.verbose = true;
51  calib_params.optimize_k1 = true;
52  calib_params.optimize_k2 = true;
53 
54  // Load images:
55  const size_t nPairs = (argc >> 1);
56  for (size_t i = 0; i < nPairs; i++)
57  {
58  const string sImgL = argv[1 + 2 * i + 0];
59  const string sImgR = argv[1 + 2 * i + 1];
60  ASSERT_FILE_EXISTS_(sImgL);
61  ASSERT_FILE_EXISTS_(sImgR);
62 
63  calib_imgs.resize(calib_imgs.size() + 1);
64  TImageStereoCalibData& stereo_dat = *calib_imgs.rbegin();
65 
66 #if 1
67  // Load all images in memory:
68  if (!stereo_dat.left.img_original.loadFromFile(sImgL))
69  THROW_EXCEPTION_FMT("Error loading: %s", sImgL.c_str());
70  if (!stereo_dat.right.img_original.loadFromFile(sImgR))
71  THROW_EXCEPTION_FMT("Error loading: %s", sImgR.c_str());
72 #else
73  // Don't load images in memory until really needed.
74  stereo_dat.left.img_original.setExternalStorage(sImgL);
75  stereo_dat.right.img_original.setExternalStorage(sImgR);
76 #endif
77  }
78 
79  // Run calibration:
81  calib_imgs, calib_params, calib_result);
82 
83  if (!res)
84  {
85  std::cout << "Calibration returned an error status.\n";
86  return -1;
87  }
88  else
89  {
90  // Calibration was OK:
91 
92  // Show detected corners:
93  if (true)
94  {
95  mrpt::gui::CDisplayWindow3D win("Calibration results", 1000, 480);
96 
98  {
100  win.get3DSceneAndLock();
101  view1 = scene->getViewport("main");
102  view2 = scene->createViewport("right");
103 
104  // Split viewing area into two halves:
105  view1->setViewportPosition(0, 0, 0.5, 1.0);
106  view2->setViewportPosition(0.5, 0, 0.5, 1.0);
107 
108  win.unlockAccess3DScene();
109  }
110 
111  for (size_t i = 0; i < nPairs; i++)
112  {
113  win.get3DSceneAndLock();
114 
115  view1->setImageView(
116  calib_imgs[i].left.img_rectified); // img_checkboard );
117  view2->setImageView(
118  calib_imgs[i].right.img_rectified); // img_checkboard );
119 
120  win.setWindowTitle(mrpt::format(
121  "Detected corners: %u / %u",
122  static_cast<unsigned int>(i + 1),
123  static_cast<unsigned int>(nPairs)));
124 
125  win.unlockAccess3DScene();
126  win.repaint();
127 
128  win.waitForKey();
129  }
130  } // end show detected corners
131 
132  return 0;
133  }
134 }
135 
136 // ------------------------------------------------------
137 // MAIN
138 // ------------------------------------------------------
139 int main(int argc, char** argv)
140 {
141  try
142  {
143  return TestStereoCalibrate(argc, argv);
144  }
145  catch (const std::exception& e)
146  {
147  std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
148  return -1;
149  }
150  catch (...)
151  {
152  printf("Untyped exception!!");
153  return -1;
154  }
155 }
filesystem.h
mrpt::vision::TStereoCalibParams::optimize_k2
bool optimize_k2
Definition: chessboard_stereo_camera_calib.h:79
mrpt::vision::TImageStereoCalibData::left
TImageCalibData left
Definition: chessboard_stereo_camera_calib.h:31
mrpt::system::CTimeLogger
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X),...
Definition: system/CTimeLogger.h:50
mrpt::vision::TStereoCalibParams::check_size_y
unsigned int check_size_y
Definition: chessboard_stereo_camera_calib.h:58
mrpt::vision::checkerBoardStereoCalibration
bool checkerBoardStereoCalibration(TCalibrationStereoImageList &images, const TStereoCalibParams &params, TStereoCalibResults &out_results)
Optimize the calibration parameters of a stereo camera or a RGB+D (Kinect) camera.
Definition: chessboard_stereo_camera_calib.cpp:44
mrpt::vision::TImageStereoCalibData::right
TImageCalibData right
Definition: chessboard_stereo_camera_calib.h:31
mrpt::vision
Copyright (C) 2010 Hauke Strasdat Imperial College London Copyright (c) 2005-2020,...
Definition: bundle_adjustment.h:35
mrpt::vision::TStereoCalibParams
Input parameters for mrpt::vision::checkerBoardStereoCalibration.
Definition: chessboard_stereo_camera_calib.h:55
chessboard_stereo_camera_calib.h
mrpt::vision::TImageStereoCalibData
Data associated to each stereo image in the calibration process mrpt::vision::checkerBoardCameraCalib...
Definition: chessboard_stereo_camera_calib.h:29
mrpt::vision::TStereoCalibParams::check_squares_length_X_meters
double check_squares_length_X_meters
The size of each square in the checkerboard, in meters, in the "X" & Y" axes.
Definition: chessboard_stereo_camera_calib.h:61
THROW_EXCEPTION_FMT
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:69
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
CDisplayWindow3D.h
mrpt::vision::TImageCalibData::img_original
mrpt::img::CImage img_original
This image will be automatically loaded from the file name passed to checkerBoardCameraCalibration.
Definition: chessboard_camera_calib.h:32
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::vision::TStereoCalibParams::check_size_x
unsigned int check_size_x
The number of squares in the checkerboard in the "X" & "Y" direction.
Definition: chessboard_stereo_camera_calib.h:58
mrpt::opengl::COpenGLViewport::Ptr
std::shared_ptr< mrpt::opengl ::COpenGLViewport > Ptr
Definition: COpenGLViewport.h:65
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
argv
const char * argv[]
Definition: RawlogGrabberApp_unittest.cpp:40
mrpt::vision::TStereoCalibResults
Output results for mrpt::vision::checkerBoardStereoCalibration.
Definition: chessboard_stereo_camera_calib.h:100
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
TestStereoCalibrate
int TestStereoCalibrate(int argc, char **argv)
Definition: vision_stereo_rectify/test.cpp:27
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< mrpt::opengl ::COpenGLScene > Ptr
Definition: COpenGLScene.h:58
argc
const int argc
Definition: RawlogGrabberApp_unittest.cpp:41
CTimeLogger.h
mrpt::vision::TCalibrationStereoImageList
std::vector< TImageStereoCalibData > TCalibrationStereoImageList
A list of images, used in checkerBoardStereoCalibration.
Definition: chessboard_stereo_camera_calib.h:137
mrpt::img::CImage::setExternalStorage
void setExternalStorage(const std::string &fileName) noexcept
By using this method the image is marked as referenced to an external file, which will be loaded only...
Definition: CImage.cpp:1571
mrpt::vision::TStereoCalibParams::check_squares_length_Y_meters
double check_squares_length_Y_meters
Definition: chessboard_stereo_camera_calib.h:62
mrpt::exception_to_str
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
mrpt::img::CImage::loadFromFile
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV).
Definition: CImage.cpp:305
ASSERT_FILE_EXISTS_
#define ASSERT_FILE_EXISTS_(FIL)
Definition: filesystem.h:22
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117
mrpt::format
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
mrpt::system
Definition: backtrace.h:14
mrpt::vision::TStereoCalibParams::optimize_k1
bool optimize_k1
Select which distortion parameters (of both left/right cameras) will be optimzed: k1,...
Definition: chessboard_stereo_camera_calib.h:79



Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 23:51:15 UTC 2020