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 
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
144 
145 #endif /* STEREOCAMERAMODEL_H_ */
void serialize(const Eigen::Matrix< S, T, U > &mat, std::ostream &strm)
const cv::Mat & R() const
bool isRectificationMapInitialized() const
GLM_FUNC_DECL detail::tmat4x4< T, P > scale(detail::tmat4x4< T, P > const &m, detail::tvec3< T, P > const &v)
const cv::Mat & F() const
const std::string & getRightSuffix() const
#define RTABMAP_EXP
Definition: RtabmapExp.h:38
const CameraModel & left() const
const cv::Mat & T() const
const cv::Mat & E() const
bool isValidForRectification() const
const CameraModel & right() const
void setLocalTransform(const Transform &transform)
void setImageSize(const cv::Size &size)
const std::string & getLeftSuffix() const
const Transform & localTransform() const
void deserialize(std::istream &strm, Eigen::Matrix< S, T, U > *mat)
const std::string & name() const


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Dec 14 2020 03:37:06