MRPT  2.0.0
CUndistortMap.h
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 #pragma once
10 
11 #include <mrpt/img/CImage.h>
12 #include <mrpt/img/TCamera.h>
13 
14 namespace mrpt::vision
15 {
16 /** Use this class to undistort monocular images if the same distortion map is
17  * used over and over again.
18  * Using this class is much more efficient that calling
19  * mrpt::img::CImage::rectifyImage or OpenCV's cvUndistort2(), since
20  * the remapping data is computed only once for the camera parameters (typical
21  * times: 640x480 image -> 70% build map / 30% actual undistort).
22  *
23  * Works with grayscale or color images.
24  *
25  * Example of usage:
26  * \code
27  * CUndistortMap unmap;
28  * mrpt::img::TCamera cam_params;
29  *
30  * unmap.setFromCamParams( cam_params );
31  *
32  * mrpt::img::CImage img, img_out;
33  *
34  * while (true) {
35  * unmap.undistort(img, img_out); // or:
36  * unmap.undistort(img); // output in place
37  * }
38  *
39  * \endcode
40  *
41  * \sa CStereoRectifyMap, mrpt::img::TCamera, the application <a
42  * href="http://www.mrpt.org/Application:camera-calib" >camera-calib</a> for
43  * calibrating a camera.
44  * \ingroup mrpt_vision_grp
45  */
47 {
48  public:
49  /** Default ctor */
50  CUndistortMap();
51 
52  /** Prepares the mapping from the distortion parameters of a camera.
53  * Must be called before invoking \a undistort().
54  */
56 
57  /** Undistort the input image and saves the result in the output one - \a
58  * setFromCamParams() must have been set prior to calling this.
59  */
60  void undistort(
61  const mrpt::img::CImage& in_img, mrpt::img::CImage& out_img) const;
62 
63  /** Undistort the input image and saves the result in-place- \a
64  * setFromCamParams() must have been set prior to calling this.
65  */
66  void undistort(mrpt::img::CImage& in_out_img) const;
67 
68  /** Returns the camera parameters which were used to generate the distortion
69  * map, as passed by the user to \a setFromCamParams */
70  inline const mrpt::img::TCamera& getCameraParams() const
71  {
72  return m_camera_params;
73  }
74 
75  /** Returns true if \a setFromCamParams() has been already called, false
76  * otherwise.
77  * Can be used within loops to determine the first usage of the object and
78  * when it needs to be initialized.
79  */
80  inline bool isSet() const { return !m_dat_mapx.empty(); }
81 
82  private:
83  std::vector<int16_t> m_dat_mapx;
84  std::vector<uint16_t> m_dat_mapy;
85 
86  /** A copy of the data provided by the user */
88 
89 }; // end class
90 } // namespace mrpt::vision
void setFromCamParams(const mrpt::img::TCamera &params)
Prepares the mapping from the distortion parameters of a camera.
bool isSet() const
Returns true if setFromCamParams() has been already called, false otherwise.
Definition: CUndistortMap.h:80
mrpt::vision::TStereoCalibParams params
void undistort(const mrpt::img::CImage &in_img, mrpt::img::CImage &out_img) const
Undistort the input image and saves the result in the output one - setFromCamParams() must have been ...
std::vector< uint16_t > m_dat_mapy
Definition: CUndistortMap.h:84
Classes for computer vision, detectors, features, etc.
Definition: CDifodo.h:17
Parameters for the Brown-Conrady camera lens distortion model.
Definition: TCamera.h:26
CUndistortMap()
Default ctor.
const mrpt::img::TCamera & getCameraParams() const
Returns the camera parameters which were used to generate the distortion map, as passed by the user t...
Definition: CUndistortMap.h:70
Use this class to undistort monocular images if the same distortion map is used over and over again...
Definition: CUndistortMap.h:46
std::vector< int16_t > m_dat_mapx
Definition: CUndistortMap.h:83
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
mrpt::img::TCamera m_camera_params
A copy of the data provided by the user.
Definition: CUndistortMap.h:87



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020