28 #ifndef CAMERAMODEL_H_
29 #define CAMERAMODEL_H_
31 #include <opencv2/opencv.hpp>
33 #include "rtabmap/core/rtabmap_core_export.h"
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 bool initRectificationMap();
91 return imageSize_.width>0 &&
92 imageSize_.height>0 &&
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;
129 bool load(
const std::string & filePath);
130 bool load(
const std::string & directory,
const std::string & cameraName);
131 bool save(
const std::string & directory)
const;
132 std::vector<unsigned char>
serialize()
const;
133 unsigned int deserialize(
const std::vector<unsigned char>& data);
134 unsigned int deserialize(
const unsigned char * data,
unsigned int dataSize);
140 cv::Mat rectifyImage(
const cv::Mat & raw,
int interpolation = cv::INTER_LINEAR)
const;
141 cv::Mat rectifyDepth(
const cv::Mat & raw)
const;
144 void project(
float u,
float v,
float depth,
float & x,
float & y,
float & z)
const;
146 void reproject(
float x,
float y,
float z,
float & u,
float & v)
const;
147 void reproject(
float x,
float y,
float z,
int & u,
int & v)
const;
148 bool inFrame(
int u,
int v)
const;