28 #ifndef CAMERAMODEL_H_ 29 #define CAMERAMODEL_H_ 31 #include <opencv2/opencv.hpp> 45 static Transform opticalRotation() {
return Transform(0,0,1,0, -1,0,0,0, 0,-1,0,0);}
54 const std::string & name,
55 const cv::Size & imageSize,
60 const Transform & localTransform = opticalRotation());
68 const Transform & localTransform = opticalRotation(),
70 const cv::Size & imageSize = cv::Size(0,0));
73 const std::string & name,
78 const Transform & localTransform = opticalRotation(),
80 const cv::Size & imageSize = cv::Size(0,0));
84 void initRectificationMap();
88 bool isValidForReprojection()
const {
return fx()>0.0 && fy()>0.0 && cx()>0.0 && cy()>0.0 && imageWidth()>0 && imageHeight()>0;}
91 return imageSize_.width>0 &&
92 imageSize_.height>0 &&
99 void setName(
const std::string & name) {name_=name;}
100 const std::string &
name()
const {
return name_;}
102 double fx()
const {
return P_.empty()?K_.empty()?0.0:K_.at<
double>(0,0):P_.at<
double>(0,0);}
103 double fy()
const {
return P_.empty()?K_.empty()?0.0:K_.at<
double>(1,1):P_.at<
double>(1,1);}
104 double cx()
const {
return P_.empty()?K_.empty()?0.0:K_.at<
double>(0,2):P_.at<
double>(0,2);}
105 double cy()
const {
return P_.empty()?K_.empty()?0.0:K_.at<
double>(1,2):P_.at<
double>(1,2);}
106 double Tx()
const {
return P_.empty()?0.0:P_.at<
double>(0,3);}
110 cv::Mat
K()
const {
return !P_.empty()?P_.colRange(0,3):K_;}
111 cv::Mat
D()
const {
return P_.empty()&&!D_.empty()?D_:cv::Mat::zeros(1,5,CV_64FC1);}
112 cv::Mat
R()
const {
return R_;}
113 cv::Mat
P()
const {
return P_;}
118 void setImageSize(
const cv::Size & size);
125 double horizontalFOV()
const;
126 double verticalFOV()
const;
128 bool load(
const std::string & filePath);
129 bool load(
const std::string & directory,
const std::string & cameraName);
130 bool save(
const std::string & directory)
const;
131 std::vector<unsigned char>
serialize()
const;
132 unsigned int deserialize(
const std::vector<unsigned char>& data);
133 unsigned int deserialize(
const unsigned char * data,
unsigned int dataSize);
139 cv::Mat rectifyImage(
const cv::Mat & raw,
int interpolation = cv::INTER_LINEAR)
const;
140 cv::Mat rectifyDepth(
const cv::Mat & raw)
const;
143 void project(
float u,
float v,
float depth,
float & x,
float & y,
float & z)
const;
145 void reproject(
float x,
float y,
float z,
float & u,
float & v)
const;
146 void reproject(
float x,
float y,
float z,
int & u,
int & v)
const;
147 bool inFrame(
int u,
int v)
const;
void setLocalTransform(const Transform &transform)
bool isRectificationMapInitialized() const
const cv::Size & imageSize() const
void serialize(const Eigen::Matrix< S, T, U > &mat, std::ostream &strm)
const std::string & name() const
Transform localTransform_
static Transform opticalRotation()
bool isValidForRectification() const
bool isValidForReprojection() const
bool isValidForProjection() const
RTABMAP_EXP std::ostream & operator<<(std::ostream &os, const CameraModel &model)
void setName(const std::string &name)
void deserialize(std::istream &strm, Eigen::Matrix< S, T, U > *mat)
const Transform & localTransform() const