S1. 采用matlab标定工具箱进行左、右相机单目和双目标定;
S2. 根据标定结果计算校正旋转矩阵、投影矩阵、重投影矩阵Q;
S3. 根据校正旋转矩阵、投影矩阵,计算映射表,校正图像使其共面、共行;
S4. 采用SGBM计算视差disp;
S5. 根据重投影矩阵Q和视差disp,计算三维坐标点;
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
const int imageWidth = 320; //摄像头的分辨率
const int imageHeight = 240;
Size imageSize = Size(imageWidth, imageHeight);
Mat grayImageL, grayImageR;
Mat rectifyImageL, rectifyImageR;
Rect validROIL;//图像校正之后,会对图像进行裁剪,这里的validROI就是指裁剪之后的区域, 其内部的所有像素都有效
Rect validROIR;
Mat mapLx, mapLy, mapRx, mapRy; //映射表
Mat Rl, Rr, Pl, Pr, Q; //校正旋转矩阵R,投影矩阵P 重投影矩阵Q
Mat matlab_cameraMatrixL;
Mat matlab_distCoeffL;
Mat matlab_cameraMatrixR;
Mat matlab_distCoeffR;
Mat matlab_Rl, matlab_Rr, matlab_Pl, matlab_Pr, matlab_R, matlab_T;
Mat R;
/*****立体匹配*****/
voi