Hi,
I’m currently working on a stereo video recording with a rather bad calibration : once undistorted/rectified, the right image is shifted 4 (more precisely 3.8) pixels down (ie on all left-right features matchings, the feature on the right image is 4 lines further down than on the left image).
Is there a simple way to modify the calibration data to compensate for this shift?
Thanks a lot in advance
Felix
PS : the relevant code :
std::vector<double> left_distortion_coeffs={0.1665669107651682, 0.575877741854227, 0.006379205470310661, -0.0017993439560661756};
std::vector<double> right_distortion_coeffs={0.16815689863584243, 0.5655897303367851, -1.5218607763842107e-05, 0.0035169653281324404};
//left intrinsic matrix
double l_fx=1757.703579674525;
double l_fy=1754.2733000318983;
double l_cx=1037.3544528564566;
double l_cy=754.8546950404783;
cv::Mat left_camera_intrinsics =(cv::Mat_<double>(3,3) << l_fx, 0 , l_cx,
0 , l_fy, l_cy,
0 , 0 , 1.0);
//right intrinsic matrix
double r_fx=1757.1453747841483;
double r_fy=1752.4718777207768;
double r_cx=1023.6665754970669;
double r_cy=759.2776943745199;
cv::Mat right_camera_intrinsics=(cv::Mat_<double>(3,3) << r_fx, 0 , r_cx,
0 , r_fy, r_cy,
0 , 0 , 1.0);
//transform between cameras (transformation from left frame (cnm1) to right frame(cn))
cv::Mat T_left_to_right=(cv::Mat_<double>(4,4)<<
0.9993110889219513, 0.03710161562579457, 0.00090425415455681, -0.19492944401815318,
-0.03711081358058976, 0.9992067184844753, 0.01444718833785609, 0.006302996103602742,
-0.00036752279786606565, -0.014470793117122745, 0.9998952250478801, 0.0020179296721928395,
0.0, 0.0, 0.0, 1.0);
double alpha=0; //all pixels in resulting image are valide (but we loose some pixels)
Mat new_left_intrinsic_matrix = cv::getOptimalNewCameraMatrix(left_camera_intrinsics,
left_distortion_coeffs,
im_size,
alpha);
Mat new_right_intrinsic_matrix = cv::getOptimalNewCameraMatrix(right_camera_intrinsics,
right_distortion_coeffs,
im_size,
alpha);
Mat R1, R2, P1, P2, Q;
cv::stereoRectify(new_left_intrinsic_matrix,
left_distortion_coeffs,
new_right_intrinsic_matrix,
right_distortion_coeffs,
im_size,
R_left_to_right,
Translation_left_to_right,
R1,
R2,
P1,
P2,
Q,
cv::CALIB_ZERO_DISPARITY,
alpha);
cv::Mat Left_Stereo_Map1, Left_Stereo_Map2;
cv::Mat Right_Stereo_Map1, Right_Stereo_Map2;
mapping_m1type=CV_32FC1;
cv::initUndistortRectifyMap(new_left_intrinsic_matrix,
left_distortion_coeffs,
R1,
P1,
im_size,
mapping_m1type,
Left_Stereo_Map1,
Left_Stereo_Map2);
cv::initUndistortRectifyMap(new_right_intrinsic_matrix,
right_distortion_coeffs,
R2,
P2,
im_size,
mapping_m1type,
Right_Stereo_Map1,
Right_Stereo_Map2);