15 #include <mrpt/otherlibs/do_opencv_includes.h> 30 m_camera_params = campar;
33 double aux1[3][3], aux2[1][5];
34 for (
int i = 0; i < 3; i++)
36 for (
int i = 0; i < 5; i++) aux2[0][i] = campar.
dist[i];
38 const cv::Mat inMat(3, 3, CV_64F, aux1);
39 const cv::Mat distM(1, 5, CV_64F, aux2);
41 m_dat_mapx.resize(2 * campar.
nrows * campar.
ncols);
42 m_dat_mapy.resize(campar.
nrows * campar.
ncols);
44 cv::Mat mapx(campar.
nrows, campar.
ncols, CV_16SC2, &m_dat_mapx[0]);
45 cv::Mat mapy(campar.
nrows, campar.
ncols, CV_16UC1, &m_dat_mapy[0]);
47 cv::initUndistortRectifyMap(
48 inMat, distM, cv::Mat(), inMat, mapx.size(), mapx.type(), mapx, mapy);
62 if (m_dat_mapx.empty())
64 "Error: setFromCamParams() must be called prior to undistort().");
69 m_camera_params.nrows, m_camera_params.ncols, CV_16SC2,
70 const_cast<int16_t*>(&m_dat_mapx[0]));
72 m_camera_params.nrows, m_camera_params.ncols, CV_16UC1,
73 const_cast<uint16_t*>(&m_dat_mapy[0]));
80 mapx, mapy, INTER_LINEAR);
91 if (m_dat_mapx.empty())
93 "Error: setFromCamParams() must be called prior to undistort().");
97 m_camera_params.nrows, m_camera_params.ncols, CV_16SC2,
98 const_cast<int16_t*>(&m_dat_mapx[0]));
100 m_camera_params.nrows, m_camera_params.ncols, CV_16UC1,
101 const_cast<uint16_t*>(&m_dat_mapy[0]));
104 cv::Mat out(
in.size(),
in.type());
106 cv::remap(
in, out, mapx, mapy, cv::INTER_LINEAR);
Shallow copy: the copied object is a reference to the original one.
void setFromCamParams(const mrpt::img::TCamera ¶ms)
Prepares the mapping from the distortion parameters of a camera.
#define THROW_EXCEPTION(msg)
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB)
size_t getHeight() const override
Returns the height of the image in pixels.
void asCvMat(cv::Mat &out_img, copy_type_t copy_type) const
Makes a shallow or deep copy of this image into the provided cv::Mat.
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
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 ...
size_t getWidth() const override
Returns the width of the image in pixels.
void resize(std::size_t width, std::size_t height, TImageChannels nChannels, PixelDepth depth=PixelDepth::D8U)
Changes the size of the image, erasing previous contents (does NOT scale its current content...
Classes for computer vision, detectors, features, etc.
Structure to hold the parameters of a pinhole camera model.
std::array< double, 5 > dist
[k1 k2 t1 t2 k3] -> k_i: parameters of radial distortion, t_i: parameters of tangential distortion (d...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CUndistortMap()
Default ctor.
uint32_t ncols
Camera resolution.
A class for storing images as grayscale or RGB bitmaps.