14 #include <mrpt/otherlibs/do_opencv_includes.h> 28 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM >= 0x200 29 m_camera_params = campar;
32 double aux1[3][3], aux2[1][5];
33 for (
int i = 0; i < 3; i++)
35 for (
int i = 0; i < 5; i++) aux2[0][i] = campar.
dist[i];
37 const cv::Mat inMat(3, 3, CV_64F, aux1);
38 const cv::Mat distM(1, 5, CV_64F, aux2);
40 m_dat_mapx.resize(2 * campar.
nrows * campar.
ncols);
41 m_dat_mapy.resize(campar.
nrows * campar.
ncols);
43 CvMat mapx = cvMat(campar.
nrows, campar.
ncols, CV_16SC2, &m_dat_mapx[0]);
44 CvMat mapy = cvMat(campar.
nrows, campar.
ncols, CV_16UC1, &m_dat_mapy[0]);
46 cv::Mat _mapx = cv::cvarrToMat(&mapx,
false);
47 cv::Mat _mapy = cv::cvarrToMat(&mapy,
false);
49 cv::initUndistortRectifyMap(
50 inMat, distM, cv::Mat(), inMat, _mapx.size(), _mapx.type(), _mapx,
65 if (m_dat_mapx.empty())
67 "Error: setFromCamParams() must be called prior to undistort().")
69 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM >= 0x200 71 m_camera_params.nrows, m_camera_params.ncols, CV_16SC2,
75 m_camera_params.nrows, m_camera_params.ncols, CV_16UC1,
76 const_cast<uint16_t*>(&m_dat_mapy[0]));
78 const IplImage* srcImg = in_img.
getAs<IplImage>();
80 cvCreateImage(cvGetSize(srcImg), srcImg->depth, srcImg->nChannels);
81 cvRemap(srcImg, outImg, &mapx, &mapy);
95 if (m_dat_mapx.empty())
97 "Error: setFromCamParams() must be called prior to undistort().")
99 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM >= 0x200 101 m_camera_params.nrows, m_camera_params.ncols, CV_16SC2,
102 const_cast<int16_t*>(
105 m_camera_params.nrows, m_camera_params.ncols, CV_16UC1,
106 const_cast<uint16_t*>(&m_dat_mapy[0]));
108 const IplImage* srcImg = in_out_img.
getAs<IplImage>();
110 cvCreateImage(cvGetSize(srcImg), srcImg->depth, srcImg->nChannels);
111 cvRemap(srcImg, outImg, &mapx, &mapy);
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.
void setFromCamParams(const mrpt::img::TCamera ¶ms)
Prepares the mapping from the distortion parameters of a camera.
#define THROW_EXCEPTION(msg)
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 ...
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.
void setFromIplImage(void *iplImage)
Reads the image from a OpenCV IplImage object (WITHOUT making a copy).
A class for storing images as grayscale or RGB bitmaps.