RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
StereoCameraModel.h
1/*
2Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Universite de Sherbrooke nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef STEREOCAMERAMODEL_H_
29#define STEREOCAMERAMODEL_H_
30
31#include <rtabmap/core/CameraModel.h>
32
33namespace rtabmap {
34
53class RTABMAP_CORE_EXPORT StereoCameraModel
54{
55public:
59 StereoCameraModel() : leftSuffix_("left"), rightSuffix_("right") {}
60
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));
100
125 const std::string & name,
126 const CameraModel & leftCameraModel,
127 const CameraModel & rightCameraModel,
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());
132
157 const std::string & name,
158 const CameraModel & leftCameraModel,
159 const CameraModel & rightCameraModel,
160 const Transform & extrinsics);
161
181 double fx,
182 double fy,
183 double cx,
184 double cy,
185 double baseline,
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));
188
207 const std::string & name,
208 double fx,
209 double fy,
210 double cx,
211 double cy,
212 double baseline,
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));
215
220
224 bool isValidForProjection() const {return left_.isValidForProjection() && right_.isValidForProjection() && baseline() > 0.0;}
225
229 bool isValidForRectification() const {return left_.isValidForRectification() && right_.isValidForRectification();}
230
234 void initRectificationMap() {left_.initRectificationMap(); right_.initRectificationMap();}
235
239 bool isRectificationMapInitialized() const {return left_.isRectificationMapInitialized() && right_.isRectificationMapInitialized();}
240
253 void setName(const std::string & name, const std::string & leftSuffix = "left", const std::string & rightSuffix = "right");
254
258 const std::string & name() const {return name_;}
259
263 void setImageSize(const cv::Size & size) {left_.setImageSize(size); right_.setImageSize(size);}
264
284 bool load(const std::string & directory, const std::string & cameraName, bool ignoreStereoTransform = true, bool initRectificationMaps = true);
285
299 bool save(const std::string & directory, bool ignoreStereoTransform = true) const;
300
315 bool saveStereoTransform(const std::string & directory) const;
316
330 std::vector<unsigned char> serialize() const;
331
343 unsigned int deserialize(const std::vector<unsigned char>& data);
344
365 unsigned int deserialize(const unsigned char * data, unsigned int dataSize);
366
378 double baseline() const {return right_.fx()!=0.0 && left_.fx() != 0.0 ? left_.Tx() / left_.fx() - right_.Tx()/right_.fx():0.0;}
379
395 float computeDepth(float disparity) const;
396
411 float computeDisparity(float depth) const; // m
412
428 float computeDisparity(unsigned short depth) const; // mm
429
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_;}
434
447 void scale(double scale);
448
461 void roi(const cv::Rect & roi);
462
466 void setLocalTransform(const Transform & transform) {left_.setLocalTransform(transform);}
467
471 const Transform & localTransform() const {return left_.localTransform();}
472
498
502 const CameraModel & left() const {return left_;}
506 const CameraModel & right() const {return right_;}
507
511 const std::string & getLeftSuffix() const {return leftSuffix_;}
515 const std::string & getRightSuffix() const {return rightSuffix_;}
516
517private:
528 void updateStereoRectification();
529
530private:
531 std::string leftSuffix_;
532 std::string rightSuffix_;
533 CameraModel left_;
534 CameraModel right_;
535 std::string name_;
536
537 cv::Mat R_;
538 cv::Mat T_;
539 cv::Mat E_;
540 cv::Mat F_;
541};
542
556RTABMAP_CORE_EXPORT std::ostream& operator<<(std::ostream& os, const StereoCameraModel& model);
557
558} // rtabmap
559
560#endif /* STEREOCAMERAMODEL_H_ */
Represents a pinhole camera model containing intrinsic and extrinsic parameters, used for projection,...
Definition CameraModel.h:53
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.
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53
RTABMAP_CORE_EXPORT std::ostream & operator<<(std::ostream &os, const CameraModel &model)
Stream operator for printing a camera model to an output stream.