MRPT
2.0.4
|
Use this class to rectify stereo images if the same distortion maps are reused over and over again.
The rectify maps are cached internally and only computed once for the camera parameters. The stereo camera calibration must be supplied in a mrpt::util::TStereoCamera structure (which provides method for loading from a plain text config file) or directly from the parameters of a mrpt::obs::CObservationStereoImages object.
Remember that the rectified images have a different set of intrinsic parameters than the original images, which can be retrieved with getRectifiedImageParams()
Works with grayscale or color images.
Refer to the program stereo-calib-gui for a tool that generates the required stereo camera parameters from a set of stereo images of a checkerboard.
Example of usage with mrpt::obs::CObservationStereoImages:
Read also the tutorial page online: https://www.mrpt.org/Rectifying_stereo_images
Definition at line 74 of file CStereoRectifyMap.h.
#include <mrpt/vision/CStereoRectifyMap.h>
Public Member Functions | |
CStereoRectifyMap ()=default | |
Rectify map preparation and setting/getting of parameters | |
bool | isSet () const |
Returns true if setFromCamParams() has been already called, false otherwise. More... | |
void | setFromCamParams (const mrpt::img::TStereoCamera ¶ms) |
Prepares the mapping from the intrinsic, distortion and relative pose parameters of a stereo camera. More... | |
void | setFromCamParams (const mrpt::obs::CObservationStereoImages &stereo_obs) |
A wrapper to setFromCamParams() which takes the parameters from an stereo observation object. More... | |
const mrpt::img::TStereoCamera & | getCameraParams () const |
Returns the camera parameters which were used to generate the distortion map, as passed by the user to setFromCamParams. More... | |
const mrpt::img::TStereoCamera & | getRectifiedImageParams () const |
After computing the rectification maps, this method retrieves the calibration parameters of the rectified images (which won't have any distortion). More... | |
const mrpt::img::TCamera & | getRectifiedLeftImageParams () const |
Just like getRectifiedImageParams() but for the left camera only. More... | |
const mrpt::img::TCamera & | getRectifiedRightImageParams () const |
Just like getRectifiedImageParams() but for the right camera only. More... | |
void | setAlpha (double alpha) |
Sets the alpha parameter which controls the zoom in/out of the rectified images, such that: More... | |
double | getAlpha () const |
Return the alpha parameter. More... | |
void | enableResizeOutput (bool enable, unsigned int target_width=0, unsigned int target_height=0) |
If enabled, the computed maps will rectify images to a size different than their original size. More... | |
bool | isEnabledResizeOutput () const |
Returns whether resizing is enabled (default=false) More... | |
mrpt::img::TImageSize | getResizeOutputSize () const |
Only when isEnabledResizeOutput() returns true, this gets the target size. More... | |
void | setInterpolationMethod (const mrpt::img::TInterpolationMethod interp) |
Change remap interpolation method (default=Lineal). More... | |
mrpt::img::TInterpolationMethod | getInterpolationMethod () const |
Get the currently selected interpolation method. More... | |
void | enableBothCentersCoincide (bool enable=true) |
If enabled (default=false), the principal points in both output images will coincide. More... | |
bool | isEnabledBothCentersCoincide () const |
const mrpt::poses::CPose3DQuat & | getLeftCameraRot () const |
After computing the rectification maps, get the rotation applied to the left/right camera so their virtual image plane is the same after rectification. More... | |
const mrpt::poses::CPose3DQuat & | getRightCameraRot () const |
See getLeftCameraRot() More... | |
void | setRectifyMaps (const std::vector< int16_t > &left_x, const std::vector< uint16_t > &left_y, const std::vector< int16_t > &right_x, const std::vector< uint16_t > &right_y) |
Direct input access to rectify maps. More... | |
void | setRectifyMapsFast (std::vector< int16_t > &left_x, std::vector< uint16_t > &left_y, std::vector< int16_t > &right_x, std::vector< uint16_t > &right_y) |
Direct input access to rectify maps. More... | |
Rectify methods | |
void | rectify (const mrpt::img::CImage &in_left_image, const mrpt::img::CImage &in_right_image, mrpt::img::CImage &out_left_image, mrpt::img::CImage &out_right_image) const |
Rectify the input image pair and save the result in a different output images - setFromCamParams() must have been set prior to calling this. More... | |
void | rectify (mrpt::obs::CObservationStereoImages &stereo_image_observation, const bool use_internal_mem_cache=true) const |
Overloaded version for in-place rectification of image pairs stored in a mrpt::obs::CObservationStereoImages. More... | |
Private Member Functions | |
void | internal_invalidate () |
Private Attributes | |
double | m_alpha {-1} |
bool | m_resize_output {false} |
bool | m_enable_both_centers_coincide {false} |
mrpt::img::TImageSize | m_resize_output_value {0, 0} |
mrpt::img::TInterpolationMethod | m_interpolation_method |
std::vector< int16_t > | m_dat_mapx_left |
std::vector< int16_t > | m_dat_mapx_right |
std::vector< uint16_t > | m_dat_mapy_left |
std::vector< uint16_t > | m_dat_mapy_right |
mrpt::img::TStereoCamera | m_camera_params |
A copy of the data provided by the user. More... | |
mrpt::img::TStereoCamera | m_rectified_image_params |
Resulting images params. More... | |
mrpt::poses::CPose3DQuat | m_rot_left |
The rotation applied to the left/right camera so their virtual image plane is the same after rectification. More... | |
mrpt::poses::CPose3DQuat | m_rot_right |
|
default |
void CStereoRectifyMap::enableBothCentersCoincide | ( | bool | enable = true | ) |
If enabled (default=false), the principal points in both output images will coincide.
Definition at line 94 of file CStereoRectifyMap.cpp.
void CStereoRectifyMap::enableResizeOutput | ( | bool | enable, |
unsigned int | target_width = 0 , |
||
unsigned int | target_height = 0 |
||
) |
If enabled, the computed maps will rectify images to a size different than their original size.
Definition at line 84 of file CStereoRectifyMap.cpp.
|
inline |
Return the alpha parameter.
Definition at line 140 of file CStereoRectifyMap.h.
References m_alpha.
Referenced by main().
|
inline |
Returns the camera parameters which were used to generate the distortion map, as passed by the user to setFromCamParams.
Definition at line 108 of file CStereoRectifyMap.h.
References m_camera_params.
Referenced by do_rectify().
|
inline |
Get the currently selected interpolation method.
Definition at line 169 of file CStereoRectifyMap.h.
References m_interpolation_method.
|
inline |
After computing the rectification maps, get the rotation applied to the left/right camera so their virtual image plane is the same after rectification.
Definition at line 190 of file CStereoRectifyMap.h.
References m_rot_left.
const mrpt::img::TStereoCamera & CStereoRectifyMap::getRectifiedImageParams | ( | ) | const |
After computing the rectification maps, this method retrieves the calibration parameters of the rectified images (which won't have any distortion).
std::exception | If the rectification maps have not been computed. |
Definition at line 339 of file CStereoRectifyMap.cpp.
References THROW_EXCEPTION.
const mrpt::img::TCamera & CStereoRectifyMap::getRectifiedLeftImageParams | ( | ) | const |
Just like getRectifiedImageParams() but for the left camera only.
Definition at line 347 of file CStereoRectifyMap.cpp.
References THROW_EXCEPTION.
const mrpt::img::TCamera & CStereoRectifyMap::getRectifiedRightImageParams | ( | ) | const |
Just like getRectifiedImageParams() but for the right camera only.
Definition at line 354 of file CStereoRectifyMap.cpp.
References THROW_EXCEPTION.
|
inline |
Only when isEnabledResizeOutput() returns true, this gets the target size.
Definition at line 155 of file CStereoRectifyMap.h.
References m_resize_output_value.
Referenced by do_rectify().
|
inline |
|
private |
Definition at line 68 of file CStereoRectifyMap.cpp.
|
inline |
Definition at line 182 of file CStereoRectifyMap.h.
References m_enable_both_centers_coincide.
|
inline |
Returns whether resizing is enabled (default=false)
Definition at line 152 of file CStereoRectifyMap.h.
References m_resize_output.
Referenced by do_rectify().
|
inline |
Returns true if setFromCamParams() has been already called, false otherwise.
Can be used within loops to determine the first usage of the object and when it needs to be initialized.
Definition at line 86 of file CStereoRectifyMap.h.
References m_dat_mapx_left.
Referenced by do_rectify().
void CStereoRectifyMap::rectify | ( | const mrpt::img::CImage & | in_left_image, |
const mrpt::img::CImage & | in_right_image, | ||
mrpt::img::CImage & | out_left_image, | ||
mrpt::img::CImage & | out_right_image | ||
) | const |
Rectify the input image pair and save the result in a different output images - setFromCamParams() must have been set prior to calling this.
The previous contents of the output images are completely ignored, but if they are already of the correct size and type, allocation time will be saved. Recall that getRectifiedImageParams() provides you the new intrinsic parameters of these images.
std::exception | If the rectification maps have not been computed. |
Definition at line 264 of file CStereoRectifyMap.cpp.
References mrpt::img::CImage::asCvMat(), mrpt::img::CImage::asCvMatRef(), do_rectify(), mrpt::img::CImage::getChannelCount(), MRPT_END, MRPT_START, mrpt::img::CImage::resize(), and mrpt::img::SHALLOW_COPY.
Referenced by mrpt::hwdrivers::CDUO3DCamera::getObservations().
void CStereoRectifyMap::rectify | ( | mrpt::obs::CObservationStereoImages & | stereo_image_observation, |
const bool | use_internal_mem_cache = true |
||
) | const |
Overloaded version for in-place rectification of image pairs stored in a mrpt::obs::CObservationStereoImages.
Upon return, the new camera intrinsic parameters will be already stored in the observation object. If use_internal_mem_cache is set to true (recommended), will reuse over and over again the same auxiliary images (kept internally to this object) needed for in-place rectification. The only reason not to enable this cache is when multiple threads can invoke this method simultaneously.
Definition at line 303 of file CStereoRectifyMap.cpp.
References ASSERT_, mrpt::obs::CObservationStereoImages::cameraPose, mrpt::obs::CObservationStereoImages::hasImageRight, mrpt::obs::CObservationStereoImages::imageLeft, mrpt::obs::CObservationStereoImages::imageRight, mrpt::poses::CPose3DQuat::m_coords, MRPT_END, MRPT_START, mrpt::obs::CObservationStereoImages::rightCameraPose, and mrpt::obs::CObservationStereoImages::setStereoCameraParams().
void CStereoRectifyMap::setAlpha | ( | double | alpha | ) |
Sets the alpha parameter which controls the zoom in/out of the rectified images, such that:
Definition at line 77 of file CStereoRectifyMap.cpp.
void CStereoRectifyMap::setFromCamParams | ( | const mrpt::img::TStereoCamera & | params | ) |
Prepares the mapping from the intrinsic, distortion and relative pose parameters of a stereo camera.
Prepares the mapping from the distortion parameters of a camera.
Must be called before invoking rectify(). The alpha parameter can be changed with setAlpha() before invoking this method; otherwise, the current rectification maps will be marked as invalid and should be prepared again.
Must be called before invoking undistort().
Definition at line 104 of file CStereoRectifyMap.cpp.
References ASSERT_, mrpt::img::TCamera::dist, mrpt::poses::CPoseOrPoint< DERIVEDCLASS, DIM >::getInverseHomogeneousMatrix(), mrpt::img::TCamera::intrinsicParams, MRPT_END, MRPT_START, mrpt::img::TCamera::ncols, mrpt::img::TCamera::nrows, params, R, mrpt::poses::CPose3D::setRotationMatrix(), and THROW_EXCEPTION.
Referenced by main(), mrpt::hwdrivers::CDUO3DCamera::open(), and setFromCamParams().
|
inline |
A wrapper to setFromCamParams() which takes the parameters from an stereo observation object.
Definition at line 99 of file CStereoRectifyMap.h.
References mrpt::obs::CObservationStereoImages::getStereoCameraParams(), params, and setFromCamParams().
|
inline |
Change remap interpolation method (default=Lineal).
This parameter can be safely changed at any instant without consequences.
Definition at line 162 of file CStereoRectifyMap.h.
References m_interpolation_method.
void CStereoRectifyMap::setRectifyMaps | ( | const std::vector< int16_t > & | left_x, |
const std::vector< uint16_t > & | left_y, | ||
const std::vector< int16_t > & | right_x, | ||
const std::vector< uint16_t > & | right_y | ||
) |
Direct input access to rectify maps.
Definition at line 362 of file CStereoRectifyMap.cpp.
void CStereoRectifyMap::setRectifyMapsFast | ( | std::vector< int16_t > & | left_x, |
std::vector< uint16_t > & | left_y, | ||
std::vector< int16_t > & | right_x, | ||
std::vector< uint16_t > & | right_y | ||
) |
Direct input access to rectify maps.
This method swaps the vectors so the inputs are no longer available.
Definition at line 377 of file CStereoRectifyMap.cpp.
|
private |
Definition at line 259 of file CStereoRectifyMap.h.
Referenced by getAlpha().
|
private |
A copy of the data provided by the user.
Definition at line 270 of file CStereoRectifyMap.h.
Referenced by getCameraParams().
|
private |
Definition at line 266 of file CStereoRectifyMap.h.
Referenced by isSet().
|
private |
Definition at line 266 of file CStereoRectifyMap.h.
|
private |
Definition at line 267 of file CStereoRectifyMap.h.
|
private |
Definition at line 267 of file CStereoRectifyMap.h.
|
private |
Definition at line 261 of file CStereoRectifyMap.h.
Referenced by isEnabledBothCentersCoincide().
|
private |
Definition at line 263 of file CStereoRectifyMap.h.
Referenced by getInterpolationMethod(), and setInterpolationMethod().
|
private |
Resulting images params.
Definition at line 272 of file CStereoRectifyMap.h.
|
private |
Definition at line 260 of file CStereoRectifyMap.h.
Referenced by isEnabledResizeOutput().
|
private |
Definition at line 262 of file CStereoRectifyMap.h.
Referenced by getResizeOutputSize().
|
private |
The rotation applied to the left/right camera so their virtual image plane is the same after rectification.
Definition at line 276 of file CStereoRectifyMap.h.
Referenced by getLeftCameraRot().
|
private |
Definition at line 276 of file CStereoRectifyMap.h.
Referenced by getRightCameraRot().
Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020 |