00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef STEREOCAMERAMODEL_H_
00029 #define STEREOCAMERAMODEL_H_
00030
00031 #include <rtabmap/core/CameraModel.h>
00032
00033 namespace rtabmap {
00034
00035 class RTABMAP_EXP StereoCameraModel
00036 {
00037 public:
00038 StereoCameraModel() : leftSuffix_("left"), rightSuffix_("right") {}
00039 StereoCameraModel(
00040 const std::string & name,
00041 const cv::Size & imageSize1,
00042 const cv::Mat & K1, const cv::Mat & D1, const cv::Mat & R1, const cv::Mat & P1,
00043 const cv::Size & imageSize2,
00044 const cv::Mat & K2, const cv::Mat & D2, const cv::Mat & R2, const cv::Mat & P2,
00045 const cv::Mat & R, const cv::Mat & T, const cv::Mat & E, const cv::Mat & F,
00046 const Transform & localTransform = Transform::getIdentity());
00047
00048
00049 StereoCameraModel(
00050 const std::string & name,
00051 const CameraModel & leftCameraModel,
00052 const CameraModel & rightCameraModel,
00053 const cv::Mat & R = cv::Mat(),
00054 const cv::Mat & T = cv::Mat(),
00055 const cv::Mat & E = cv::Mat(),
00056 const cv::Mat & F = cv::Mat());
00057
00058 StereoCameraModel(
00059 const std::string & name,
00060 const CameraModel & leftCameraModel,
00061 const CameraModel & rightCameraModel,
00062 const Transform & extrinsics);
00063
00064
00065 StereoCameraModel(
00066 double fx,
00067 double fy,
00068 double cx,
00069 double cy,
00070 double baseline,
00071 const Transform & localTransform = Transform::getIdentity(),
00072 const cv::Size & imageSize = cv::Size(0,0));
00073
00074 StereoCameraModel(
00075 const std::string & name,
00076 double fx,
00077 double fy,
00078 double cx,
00079 double cy,
00080 double baseline,
00081 const Transform & localTransform = Transform::getIdentity(),
00082 const cv::Size & imageSize = cv::Size(0,0));
00083 virtual ~StereoCameraModel() {}
00084
00085 bool isValidForProjection() const {return left_.isValidForProjection() && right_.isValidForProjection() && baseline() > 0.0;}
00086 bool isValidForRectification() const {return left_.isValidForRectification() && right_.isValidForRectification();}
00087
00088 void initRectificationMap() {left_.initRectificationMap(); right_.initRectificationMap();}
00089 bool isRectificationMapInitialized() {return left_.isRectificationMapInitialized() && right_.isRectificationMapInitialized();}
00090
00091 void setName(const std::string & name, const std::string & leftSuffix = "left", const std::string & rightSuffix = "right");
00092 const std::string & name() const {return name_;}
00093
00094
00095 void setImageSize(const cv::Size & size) {left_.setImageSize(size); right_.setImageSize(size);}
00096
00097 bool load(const std::string & directory, const std::string & cameraName, bool ignoreStereoTransform = true);
00098 bool save(const std::string & directory, bool ignoreStereoTransform = true) const;
00099 bool saveStereoTransform(const std::string & directory) const;
00100
00101 double baseline() const {return right_.fx()!=0.0 && left_.fx() != 0.0 ? left_.Tx() / left_.fx() - right_.Tx()/right_.fx():0.0;}
00102
00103 float computeDepth(float disparity) const;
00104 float computeDisparity(float depth) const;
00105 float computeDisparity(unsigned short depth) const;
00106
00107 const cv::Mat & R() const {return R_;}
00108 const cv::Mat & T() const {return T_;}
00109 const cv::Mat & E() const {return E_;}
00110 const cv::Mat & F() const {return F_;}
00111
00112 void scale(double scale);
00113 void roi(const cv::Rect & roi);
00114
00115 void setLocalTransform(const Transform & transform) {left_.setLocalTransform(transform);}
00116 const Transform & localTransform() const {return left_.localTransform();}
00117 Transform stereoTransform() const;
00118
00119 const CameraModel & left() const {return left_;}
00120 const CameraModel & right() const {return right_;}
00121
00122 const std::string & getLeftSuffix() const {return leftSuffix_;}
00123 const std::string & getRightSuffix() const {return rightSuffix_;}
00124
00125 private:
00126 std::string leftSuffix_;
00127 std::string rightSuffix_;
00128 CameraModel left_;
00129 CameraModel right_;
00130 std::string name_;
00131 cv::Mat R_;
00132 cv::Mat T_;
00133 cv::Mat E_;
00134 cv::Mat F_;
00135 };
00136
00137 }
00138
00139 #endif