Main MRPT website > C++ reference
MRPT logo
CUndistortMap.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef mrpt_CUndistortMap_H
29 #define mrpt_CUndistortMap_H
30 
31 #include <mrpt/utils/TCamera.h>
32 #include <mrpt/utils/CImage.h>
33 
35 
36 namespace mrpt
37 {
38  namespace vision
39  {
40  /** Use this class to undistort monocular images if the same distortion map is used over and over again.
41  * Using this class is much more efficient that calling mrpt::utils::CImage::rectifyImage or OpenCV's cvUndistort2(), since
42  * the remapping data is computed only once for the camera parameters (typical times: 640x480 image -> 70% build map / 30% actual undistort).
43  *
44  * Works with grayscale or color images.
45  *
46  * Example of usage:
47  * \code
48  * CUndistortMap unmap;
49  * mrpt::utils::TCamera cam_params;
50  *
51  * unmap.setFromCamParams( cam_params );
52  *
53  * mrpt::utils::CImage img, img_out;
54  *
55  * while (true) {
56  * unmap.undistort(img, img_out); // or:
57  * unmap.undistort(img); // output in place
58  * }
59  *
60  * \endcode
61  *
62  * \sa CStereoRectifyMap, mrpt::utils::TCamera, the application <a href="http://www.mrpt.org/Application:camera-calib" >camera-calib</a> for calibrating a camera.
63  * \ingroup mrpt_vision_grp
64  */
66  {
67  public:
68  CUndistortMap(); //!< Default ctor
69 
70  /** Prepares the mapping from the distortion parameters of a camera.
71  * Must be called before invoking \a undistort().
72  */
73  void setFromCamParams(const mrpt::utils::TCamera &params);
74 
75  /** Undistort the input image and saves the result in the output one - \a setFromCamParams() must have been set prior to calling this.
76  */
77  void undistort(const mrpt::utils::CImage &in_img, mrpt::utils::CImage &out_img) const;
78 
79  /** Undistort the input image and saves the result in-place- \a setFromCamParams() must have been set prior to calling this.
80  */
81  void undistort(mrpt::utils::CImage &in_out_img) const;
82 
83  /** Returns the camera parameters which were used to generate the distortion map, as passed by the user to \a setFromCamParams */
84  inline const mrpt::utils::TCamera & getCameraParams() const { return m_camera_params; }
85 
86  /** Returns true if \a setFromCamParams() has been already called, false otherwise.
87  * Can be used within loops to determine the first usage of the object and when it needs to be initialized.
88  */
89  inline bool isSet() const { return !m_dat_mapx.empty(); }
90 
91  private:
92  std::vector<int16_t> m_dat_mapx;
93  std::vector<uint16_t> m_dat_mapy;
94 
95  mrpt::utils::TCamera m_camera_params; //!< A copy of the data provided by the user
96 
97  }; // end class
98  } // end namespace
99 } // end namespace
100 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013