19 #include <boost/make_shared.hpp> 26 cv::Mat_<double>M(3,4);
27 for (
int i = 0; i < M.rows; ++i) {
28 for (
int j = 0; j < M.cols; ++j) {
36 cv::Mat_<double>M(3,3);
37 for (
int i = 0; i < M.rows; ++i) {
38 for (
int j = 0; j < M.cols; ++j) {
46 cv::Mat_<double>M(3,5);
47 for (
int i = 0; i < M.rows; ++i) {
48 for (
int j = 0; j < M.cols; ++j) {
59 Mat3d ivtR; Vec3d ivtt;
61 calibration->SetCameraParameters(0, 0, 0, 0, 0, 0, 0, 0, ivtR, ivtt, cam_model.
rawRoi().width, cam_model.
rawRoi().height);
67 const cv::Mat_<double> distortion;
69 if (forRectifiedImages) {
70 cv::decomposeProjectionMatrix(projectionMatrix, intrinsicMatrix, R, t);
73 calibration->SetDistortion(0, 0, 0, 0);
77 const cv::Mat_<double> H = projectionMatrix.colRange(0,3) * R * intrinsicMatrix.inv();
79 const cv::Mat_<double> Rt = intrinsicMatrix.inv() * H.inv() * projectionMatrix;
84 calibration->SetDistortion(distortion(0,0), distortion(0,1), distortion(0,2), distortion(0,3));
87 calibration->SetIntrinsicBase(intrinsicMatrix(0,2), intrinsicMatrix(1,2), intrinsicMatrix(0,0), intrinsicMatrix(1,1));
90 R(0,0), R(0,1), R(0,2),
91 R(1,0), R(1,1), R(1,2),
92 R(2,0), R(2,1), R(2,2));
93 calibration->SetRotation(ivtR);
95 Math3d::SetVec(ivtt, t(0,0), t(1,0), t(2,0));
96 calibration->SetTranslation(ivtt);
134 if (forRectifiedImages) {
136 Math3d::SetMat(Hl, 1,0,0,0,1,0,0,0,1);
137 Math3d::SetMat(Hr, 1,0,0,0,1,0,0,0,1);
141 const cv::Mat_<double> rectificationMatrixLeft = (projectionMatrixLeft.colRange(0,3) * RLeft * intrinsicMatrixLeft.inv()).inv();
143 rectificationMatrixLeft(0,0), rectificationMatrixLeft(0,1), rectificationMatrixLeft(0,2),
144 rectificationMatrixLeft(1,0), rectificationMatrixLeft(1,1), rectificationMatrixLeft(1,2),
145 rectificationMatrixLeft(2,0), rectificationMatrixLeft(2,1), rectificationMatrixLeft(2,2));
147 const cv::Mat_<double> rectificationMatrixRight = (projectionMatrixRight.colRange(0,3) * RRight * intrinsicMatrixRight.inv()).inv();
149 rectificationMatrixRight(0,0), rectificationMatrixRight(0,1), rectificationMatrixRight(0,2),
150 rectificationMatrixRight(1,0), rectificationMatrixRight(1,1), rectificationMatrixRight(1,2),
151 rectificationMatrixRight(2,0), rectificationMatrixRight(2,1), rectificationMatrixRight(2,2));
154 stereoCalibration->rectificationHomographyLeft = Hl;
155 stereoCalibration->rectificationHomographyRight = Hr;
157 return stereoCalibration;
const cv::Matx33d & intrinsicMatrix() const
image_geometry::PinholeCameraModel cam_model
boost::shared_ptr< CCalibration > calibrationImpl(const image_geometry::PinholeCameraModel &cam_model, bool forRectifiedImages)
cv::Mat_< double > matx33ToMat_(const cv::Matx< double, 3, 3 > &matx)
boost::shared_ptr< CCalibration > getCalibration(bool forRectifiedImages=false) const
Get the IVT Calibration.
cv::Mat_< double > matx35ToMat_(const cv::Matx< double, 3, 5 > &matx)
const cv::Matx33d & rotationMatrix() const
bool fromCameraInfo(const sensor_msgs::CameraInfo &left, const sensor_msgs::CameraInfo &right)
Set the camera parameters from the sensor_msgs/CameraInfo messages.
bool fromCameraInfo(const sensor_msgs::CameraInfo &msg)
boost::shared_ptr< CStereoCalibration > getStereoCalibration(bool forRectifiedImages=false) const
Get the IVT StereoCalibration.
bool fromCameraInfo(const sensor_msgs::CameraInfo &msg)
Set the camera parameters from the sensor_msgs/CameraInfo messages.
const cv::Matx34d & projectionMatrix() const
const cv::Mat_< double > & distortionCoeffs() const
cv::Mat_< double > matx34ToMat_(const cv::Matx< double, 3, 4 > &matx)