首先要利用标定得到的参数,通过调用OpenCV中的函数来得到校正矩阵。
double LM[] = { 4.0178810502329486e+002, 0, 1.5950000000000000e+002, 0,4.0178810502329486e+002,1.1950000000000000e+002, 0,0, 1 }; double LD[] = { -4.5141575299933429e-001, 2.3998422552817714e-001, 1.5081252615814692e-002, 1.8419337906291466e-003, 0 }; double RM[] = { 4.0178810502329486e+002, 0, 1.5950000000000000e+002,0, 4.0178810502329486e+002, 1.1950000000000000e+002,0,0, 1 }; double RD[] = { -5.1762688060193929e-001,6.3474560985437023e-001, -2.5303249541511292e-003, -2.7165709692779268e-003, 0 }; double Rotate[] = { 9.9952858710662951e-001,1.4994693512808868e-002, 2.6791094100126738e-002,-1.1568939379481839e-002, 9.9224798371307799e-001,-1.2373398263599662e-001, -2.8438762249064085e-002, 1.2336570829767958e-001, 9.9195369792039845e-001 }; double translation[] = { -8.8108837791674333e+001, -1.3412948452799096e+000, 9.4102431499505457e+000 }; cv::Mat cameraMatrix_L = cv::Mat(3,3,CV_64FC1,LM); cv::Mat distortionCoefficients_L = cv::Mat(1,5,CV_64FC1,LD); cv::Mat cameraMatrix_R = cv::Mat(3,3,CV_64FC1,RM); cv::Mat distortionCoefficients_R = cv::Mat(1,5,CV_64FC1,RD); cv::Mat rotations= cv::Mat(3,3,CV_64FC1,Rotate); cv::Mat translations= cv::Mat(3,1,CV_64FC1,translation); cv::Mat R1, R2, P1, P2, Q; cv::Rect roi1,roi2; cv::Mat m_Calib_Mat_Remap_X_L = cv::Mat(imageSize, CV_32FC1); cv::Mat m_Calib_Mat_Remap_Y_L= cv::Mat(imageSize, CV_32FC1); cv::Mat m_Calib_Mat_Remap_X_R = cv::Mat(imageSize, CV_32FC1); cv::Mat m_Calib_Mat_Remap_Y_R = cv::Mat(imageSize, CV_32FC1); cv::stereoRectify( cameraMatrix_L, distortionCoefficients_L, cameraMatrix_R, distortionCoefficients_R, imageSize, rotations, translations, R1,R2,P1,P2,Q, 1024 ); initUndistortRectifyMap( cameraMatrix_L, distortionCoefficients_L, R1,P1, imageSize, CV_16SC2, m_Calib_Mat_Remap_X_L, m_Calib_Mat_Remap_Y_L); initUndistortRectifyMap( cameraMatrix_R, distortionCoefficients_R, R2, P2, imageSize, CV_16SC2, m_Calib_Mat_Remap_X_R,m_Calib_Mat_Remap_Y_R);