StereoCameraModel.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, 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 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON 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
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef STEREOCAMERAMODEL_H_
29 #define STEREOCAMERAMODEL_H_
30 
32 
33 namespace rtabmap {
34 
35 class RTABMAP_CORE_EXPORT StereoCameraModel
36 {
37 public:
38  StereoCameraModel() : leftSuffix_("left"), rightSuffix_("right") {}
40  const std::string & name,
41  const cv::Size & imageSize1,
42  const cv::Mat & K1, const cv::Mat & D1, const cv::Mat & R1, const cv::Mat & P1,
43  const cv::Size & imageSize2,
44  const cv::Mat & K2, const cv::Mat & D2, const cv::Mat & R2, const cv::Mat & P2,
45  const cv::Mat & R, const cv::Mat & T, const cv::Mat & E, const cv::Mat & F,
46  const Transform & localTransform = Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0));
47 
48  // if R and T are not null, left and right camera models should be valid to be rectified.
50  const std::string & name,
51  const CameraModel & leftCameraModel,
52  const CameraModel & rightCameraModel,
53  const cv::Mat & R = cv::Mat(),
54  const cv::Mat & T = cv::Mat(),
55  const cv::Mat & E = cv::Mat(),
56  const cv::Mat & F = cv::Mat());
57  // if extrinsics transform is not null, left and right camera models should be valid to be rectified.
59  const std::string & name,
60  const CameraModel & leftCameraModel,
61  const CameraModel & rightCameraModel,
62  const Transform & extrinsics);
63 
64  //minimal
66  double fx,
67  double fy,
68  double cx,
69  double cy,
70  double baseline,
71  const Transform & localTransform = Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0),
72  const cv::Size & imageSize = cv::Size(0,0));
73  //minimal to be saved
75  const std::string & name,
76  double fx,
77  double fy,
78  double cx,
79  double cy,
80  double baseline,
81  const Transform & localTransform = Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0),
82  const cv::Size & imageSize = cv::Size(0,0));
83  virtual ~StereoCameraModel() {}
84 
85  bool isValidForProjection() const {return left_.isValidForProjection() && right_.isValidForProjection() && baseline() > 0.0;}
86  bool isValidForRectification() const {return left_.isValidForRectification() && right_.isValidForRectification();}
87 
88  void initRectificationMap() {left_.initRectificationMap(); right_.initRectificationMap();}
89  bool isRectificationMapInitialized() const {return left_.isRectificationMapInitialized() && right_.isRectificationMapInitialized();}
90 
91  void setName(const std::string & name, const std::string & leftSuffix = "left", const std::string & rightSuffix = "right");
92  const std::string & name() const {return name_;}
93 
94  // backward compatibility
95  void setImageSize(const cv::Size & size) {left_.setImageSize(size); right_.setImageSize(size);}
96 
97  bool load(const std::string & directory, const std::string & cameraName, bool ignoreStereoTransform = true);
98  bool save(const std::string & directory, bool ignoreStereoTransform = true) const;
99  bool saveStereoTransform(const std::string & directory) const;
100  std::vector<unsigned char> serialize() const;
101  unsigned int deserialize(const std::vector<unsigned char>& data);
102  unsigned int deserialize(const unsigned char * data, unsigned int dataSize);
103 
104  double baseline() const {return right_.fx()!=0.0 && left_.fx() != 0.0 ? left_.Tx() / left_.fx() - right_.Tx()/right_.fx():0.0;}
105 
106  float computeDepth(float disparity) const;
107  float computeDisparity(float depth) const; // m
108  float computeDisparity(unsigned short depth) const; // mm
109 
110  const cv::Mat & R() const {return R_;} //extrinsic rotation matrix
111  const cv::Mat & T() const {return T_;} //extrinsic translation matrix
112  const cv::Mat & E() const {return E_;} //extrinsic essential matrix
113  const cv::Mat & F() const {return F_;} //extrinsic fundamental matrix
114 
115  void scale(double scale);
116  void roi(const cv::Rect & roi);
117 
118  void setLocalTransform(const Transform & transform) {left_.setLocalTransform(transform);}
119  const Transform & localTransform() const {return left_.localTransform();}
120  Transform stereoTransform() const;
121 
122  const CameraModel & left() const {return left_;}
123  const CameraModel & right() const {return right_;}
124 
125  const std::string & getLeftSuffix() const {return leftSuffix_;}
126  const std::string & getRightSuffix() const {return rightSuffix_;}
127 
128 private:
129  void updateStereoRectification();
130 
131 private:
132  std::string leftSuffix_;
133  std::string rightSuffix_;
136  std::string name_;
137  cv::Mat R_;
138  cv::Mat T_;
139  cv::Mat E_;
140  cv::Mat F_;
141 };
142 
143 RTABMAP_CORE_EXPORT std::ostream& operator<<(std::ostream& os, const StereoCameraModel& model);
144 
145 } // rtabmap
146 
147 #endif /* STEREOCAMERAMODEL_H_ */
save
save
name
rtabmap::StereoCameraModel
Definition: StereoCameraModel.h:35
rtabmap::StereoCameraModel::isRectificationMapInitialized
bool isRectificationMapInitialized() const
Definition: StereoCameraModel.h:89
rtabmap::StereoCameraModel::getLeftSuffix
const std::string & getLeftSuffix() const
Definition: StereoCameraModel.h:125
rtabmap::StereoCameraModel::T_
cv::Mat T_
Definition: StereoCameraModel.h:138
size
Index size
rtabmap::CameraModel
Definition: CameraModel.h:38
rtabmap::StereoCameraModel::E
const cv::Mat & E() const
Definition: StereoCameraModel.h:112
rtabmap::StereoCameraModel::setImageSize
void setImageSize(const cv::Size &size)
Definition: StereoCameraModel.h:95
name_
std::string name_
rtabmap::StereoCameraModel::left_
CameraModel left_
Definition: StereoCameraModel.h:134
rtabmap::StereoCameraModel::F
const cv::Mat & F() const
Definition: StereoCameraModel.h:113
rtabmap::StereoCameraModel::baseline
double baseline() const
Definition: StereoCameraModel.h:104
rtabmap::StereoCameraModel::getRightSuffix
const std::string & getRightSuffix() const
Definition: StereoCameraModel.h:126
rtabmap::StereoCameraModel::leftSuffix_
std::string leftSuffix_
Definition: StereoCameraModel.h:132
rtabmap::StereoCameraModel::E_
cv::Mat E_
Definition: StereoCameraModel.h:139
rtabmap::StereoCameraModel::setLocalTransform
void setLocalTransform(const Transform &transform)
Definition: StereoCameraModel.h:118
rtabmap::StereoCameraModel::rightSuffix_
std::string rightSuffix_
Definition: StereoCameraModel.h:133
rtabmap::StereoCameraModel::right
const CameraModel & right() const
Definition: StereoCameraModel.h:123
eigen_extensions::deserialize
void deserialize(std::istream &strm, Eigen::Matrix< S, T, U > *mat)
Definition: eigen_extensions.h:78
scale
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set set set set surface set nocontour set clabel set mapping cartesian set nohidden3d set cntrparam order set cntrparam linear set cntrparam levels auto set cntrparam points set size set set xzeroaxis lt lw set x2zeroaxis lt lw set yzeroaxis lt lw set y2zeroaxis lt lw set tics in set ticslevel set tics scale
rtabmap::StereoCameraModel::name_
std::string name_
Definition: StereoCameraModel.h:136
eigen_extensions::serialize
void serialize(const Eigen::Matrix< S, T, U > &mat, std::ostream &strm)
Definition: eigen_extensions.h:66
rtabmap::StereoCameraModel::localTransform
const Transform & localTransform() const
Definition: StereoCameraModel.h:119
rtabmap::StereoCameraModel::left
const CameraModel & left() const
Definition: StereoCameraModel.h:122
Eigen::Triplet< double >
rtabmap::StereoCameraModel::isValidForProjection
bool isValidForProjection() const
Definition: StereoCameraModel.h:85
rtabmap::StereoCameraModel::F_
cv::Mat F_
Definition: StereoCameraModel.h:140
rtabmap::StereoCameraModel::isValidForRectification
bool isValidForRectification() const
Definition: StereoCameraModel.h:86
rtabmap::Transform
Definition: Transform.h:41
rtabmap::StereoCameraModel::~StereoCameraModel
virtual ~StereoCameraModel()
Definition: StereoCameraModel.h:83
rtabmap::StereoCameraModel::R
const cv::Mat & R() const
Definition: StereoCameraModel.h:110
rtabmap::StereoCameraModel::initRectificationMap
void initRectificationMap()
Definition: StereoCameraModel.h:88
rtabmap::StereoCameraModel::name
const std::string & name() const
Definition: StereoCameraModel.h:92
rtabmap::StereoCameraModel::right_
CameraModel right_
Definition: StereoCameraModel.h:135
CameraModel.h
transform
EIGEN_DONT_INLINE void transform(const Quaternion< Scalar > &t, Data &data)
rtabmap
Definition: CameraARCore.cpp:35
rtabmap::operator<<
RTABMAP_CORE_EXPORT std::ostream & operator<<(std::ostream &os, const CameraModel &model)
Definition: CameraModel.cpp:801
rtabmap::StereoCameraModel::R_
cv::Mat R_
Definition: StereoCameraModel.h:137
trace.model
model
Definition: trace.py:4
load
NearestNeighbourSearch< T >::Matrix load(const char *fileName)
baseline
double baseline
rtabmap::StereoCameraModel::T
const cv::Mat & T() const
Definition: StereoCameraModel.h:111
rtabmap::StereoCameraModel::StereoCameraModel
StereoCameraModel()
Definition: StereoCameraModel.h:38


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jul 1 2024 02:42:39