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::getIdentity());
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::getIdentity(),
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::getIdentity(),
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() {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 
101  double baseline() const {return right_.fx()!=0.0 && left_.fx() != 0.0 ? left_.Tx() / left_.fx() - right_.Tx()/right_.fx():0.0;}
102 
103  float computeDepth(float disparity) const;
104  float computeDisparity(float depth) const; // m
105  float computeDisparity(unsigned short depth) const; // mm
106 
107  const cv::Mat & R() const {return R_;} //extrinsic rotation matrix
108  const cv::Mat & T() const {return T_;} //extrinsic translation matrix
109  const cv::Mat & E() const {return E_;} //extrinsic essential matrix
110  const cv::Mat & F() const {return F_;} //extrinsic fundamental matrix
111 
112  void scale(double scale);
113  void roi(const cv::Rect & roi);
114 
115  void setLocalTransform(const Transform & transform) {left_.setLocalTransform(transform);}
116  const Transform & localTransform() const {return left_.localTransform();}
117  Transform stereoTransform() const;
118 
119  const CameraModel & left() const {return left_;}
120  const CameraModel & right() const {return right_;}
121 
122  const std::string & getLeftSuffix() const {return leftSuffix_;}
123  const std::string & getRightSuffix() const {return rightSuffix_;}
124 
125 private:
126  std::string leftSuffix_;
127  std::string rightSuffix_;
130  std::string name_;
131  cv::Mat R_;
132  cv::Mat T_;
133  cv::Mat E_;
134  cv::Mat F_;
135 };
136 
137 } // rtabmap
138 
139 #endif /* STEREOCAMERAMODEL_H_ */
const cv::Mat & R() const
static Transform getIdentity()
Definition: Transform.cpp:364
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
const std::string & name() const


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:43:40