28#ifndef STEREOCAMERAMODEL_H_
29#define STEREOCAMERAMODEL_H_
31#include <rtabmap/core/CameraModel.h>
93 const std::string & name,
94 const cv::Size & imageSize1,
95 const cv::Mat & K1,
const cv::Mat & D1,
const cv::Mat & R1,
const cv::Mat & P1,
96 const cv::Size & imageSize2,
97 const cv::Mat & K2,
const cv::Mat & D2,
const cv::Mat & R2,
const cv::Mat & P2,
98 const cv::Mat & R,
const cv::Mat & T,
const cv::Mat & E,
const cv::Mat & F,
99 const Transform & localTransform =
Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0));
125 const std::string & name,
128 const cv::Mat & R = cv::Mat(),
129 const cv::Mat & T = cv::Mat(),
130 const cv::Mat & E = cv::Mat(),
131 const cv::Mat & F = cv::Mat());
157 const std::string & name,
186 const Transform & localTransform =
Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0),
187 const cv::Size & imageSize = cv::Size(0,0));
207 const std::string & name,
213 const Transform & localTransform =
Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0),
214 const cv::Size & imageSize = cv::Size(0,0));
224 bool isValidForProjection()
const {
return left_.isValidForProjection() && right_.isValidForProjection() && baseline() > 0.0;}
253 void setName(
const std::string & name,
const std::string & leftSuffix =
"left",
const std::string & rightSuffix =
"right");
258 const std::string &
name()
const {
return name_;}
263 void setImageSize(
const cv::Size & size) {left_.setImageSize(size); right_.setImageSize(size);}
284 bool load(
const std::string & directory,
const std::string & cameraName,
bool ignoreStereoTransform =
true,
bool initRectificationMaps =
true);
299 bool save(
const std::string & directory,
bool ignoreStereoTransform =
true)
const;
365 unsigned int deserialize(
const unsigned char * data,
unsigned int dataSize);
378 double baseline()
const {
return right_.fx()!=0.0 && left_.fx() != 0.0 ? left_.Tx() / left_.fx() - right_.Tx()/right_.fx():0.0;}
430 const cv::Mat &
R()
const {
return R_;}
431 const cv::Mat &
T()
const {
return T_;}
432 const cv::Mat &
E()
const {
return E_;}
433 const cv::Mat &
F()
const {
return F_;}
461 void roi(
const cv::Rect & roi);
528 void updateStereoRectification();
531 std::string leftSuffix_;
532 std::string rightSuffix_;
Represents a pinhole camera model containing intrinsic and extrinsic parameters, used for projection,...
A class representing a calibrated stereo camera system.
const CameraModel & left() const
Returns the left camera model.
StereoCameraModel(double fx, double fy, double cx, double cy, double baseline, const Transform &localTransform=Transform(0, 0, 1, 0, -1, 0, 0, 0, 0,-1, 0, 0), const cv::Size &imageSize=cv::Size(0, 0))
Minimal constructor using focal lengths and baseline only.
StereoCameraModel()
Default constructor. Creates an empty stereo model with default suffixes ("left", "right").
StereoCameraModel(const std::string &name, const cv::Size &imageSize1, const cv::Mat &K1, const cv::Mat &D1, const cv::Mat &R1, const cv::Mat &P1, const cv::Size &imageSize2, const cv::Mat &K2, const cv::Mat &D2, const cv::Mat &R2, const cv::Mat &P2, const cv::Mat &R, const cv::Mat &T, const cv::Mat &E, const cv::Mat &F, const Transform &localTransform=Transform(0, 0, 1, 0, -1, 0, 0, 0, 0,-1, 0, 0))
Constructs a StereoCameraModel from detailed intrinsic and extrinsic parameters for both cameras.
bool saveStereoTransform(const std::string &directory) const
Saves stereo extrinsic parameters to a YAML file in ROS format.
const cv::Mat & F() const
Fundamental matrix.
void scale(double scale)
Scales both cameras' calibration by a factor.
float computeDisparity(unsigned short depth) const
Computes the disparity value from a depth given in unsigned short format (millimeters).
const std::string & getRightSuffix() const
Gets the suffix used for the right camera calibration file.
std::vector< unsigned char > serialize() const
Serializes the stereo camera model into a byte vector.
Transform stereoTransform() const
Returns the stereo transform (left camera relative to right camera coordinate system).
float computeDepth(float disparity) const
Computes the depth (Z coordinate) from a given disparity value.
const Transform & localTransform() const
Gets the local transform from left camera to robot base.
void initRectificationMap()
Initializes the rectification maps for both cameras.
bool isValidForProjection() const
Returns true if both left and right models are valid for projection and the baseline is positive.
unsigned int deserialize(const std::vector< unsigned char > &data)
Deserializes stereo camera model data from a byte vector.
StereoCameraModel(const std::string &name, const CameraModel &leftCameraModel, const CameraModel &rightCameraModel, const Transform &extrinsics)
Constructs a StereoCameraModel from two camera models and an extrinsic Transform between them.
const std::string & getLeftSuffix() const
Gets the suffix used for the left camera calibration file.
const cv::Mat & R() const
Stereo extrinsic rotation matrix.
const cv::Mat & T() const
Stereo extrinsic translation vector.
void setImageSize(const cv::Size &size)
Sets the image size for both left and right cameras.
const cv::Mat & E() const
Essential matrix.
double baseline() const
Returns the stereo baseline in meters.
StereoCameraModel(const std::string &name, double fx, double fy, double cx, double cy, double baseline, const Transform &localTransform=Transform(0, 0, 1, 0, -1, 0, 0, 0, 0,-1, 0, 0), const cv::Size &imageSize=cv::Size(0, 0))
Minimal constructor that also sets a name, required if we want to save it to a file.
bool load(const std::string &directory, const std::string &cameraName, bool ignoreStereoTransform=true, bool initRectificationMaps=true)
Loads stereo camera calibration data from disk.
bool isRectificationMapInitialized() const
Returns true if rectification maps are initialized.
const CameraModel & right() const
Returns the right camera model.
bool save(const std::string &directory, bool ignoreStereoTransform=true) const
Saves stereo camera calibration data to disk.
void roi(const cv::Rect &roi)
Applies region-of-interest (ROI) cropping to both cameras.
bool isValidForRectification() const
Returns true if both left and right models are valid for rectification.
void setName(const std::string &name, const std::string &leftSuffix="left", const std::string &rightSuffix="right")
Sets the camera name and optional image suffixes for the left and right cameras.
const std::string & name() const
Gets the camera name.
StereoCameraModel(const std::string &name, const CameraModel &leftCameraModel, const CameraModel &rightCameraModel, const cv::Mat &R=cv::Mat(), const cv::Mat &T=cv::Mat(), const cv::Mat &E=cv::Mat(), const cv::Mat &F=cv::Mat())
Constructs a StereoCameraModel from two individual camera models and optional stereo extrinsic parame...
float computeDisparity(float depth) const
Computes the disparity value from a given depth.
void setLocalTransform(const Transform &transform)
Sets the local transform from left camera to robot base.
virtual ~StereoCameraModel()
Destructor.
unsigned int deserialize(const unsigned char *data, unsigned int dataSize)
Deserializes stereo camera model data from a raw byte array.
RTABMAP_CORE_EXPORT std::ostream & operator<<(std::ostream &os, const CameraModel &model)
Stream operator for printing a camera model to an output stream.