I am trying to use stereo cameras for 3D position detection. I took 150 clean images at different angles using a 7x12 chessboard. Calculated projection error is 0.094 and 0.097 for the left and right cameras respectively. As you can see, both the left and right cameras can be rectified quite nicely, but the image warps and rotates when I do stereo calibration+rectification. I have included relevant parts of my code below. Any thoughts on improving stereo rectification results?
.
# start code
ret, roiL, old_mtxL, mtxL, distL, _, _ = calibrate_cam('L')
ret, roiR, old_mtxR, mtxR, distR, _, _ = calibrate_cam('R')
img_ptsL,obj_pts,w,h = load_calib_points('L')
img_ptsR,obj_ptsR,w,h = load_calib_points('R')
flags = 0
flags |= cv2.CALIB_FIX_INTRINSIC
criteria_stereo= (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
rectify_scale= -1
rect_l, rect_r, proj_mat_l, proj_mat_r, Q, roiL, roiR= cv2.stereoRectify(mtxL, distL, mtxR, distR, (w,h), Rot, Trns, rectify_scale,(0,0))
Left_Stereo_Map= cv2.initUndistortRectifyMap(mtxL, distL, rect_l, proj_mat_l, (w,h), cv2.CV_16SC2)
Right_Stereo_Map= cv2.initUndistortRectifyMap(mtxR, distR, rect_r, proj_mat_r, (w,h), cv2.CV_16SC2)
xL,yL,wL,hL = roiL
xR,yR,wR,hR = roiR
ret, imgL = capL.read()
ret, imgR = capR.read()
if ret:
Left_nice= cv2.remap(imgL,Left_Stereo_Map[0],Left_Stereo_Map[1], cv2.INTER_LANCZOS4, cv2.BORDER_CONSTANT, 0)
Right_nice= cv2.remap(imgR,Right_Stereo_Map[0],Right_Stereo_Map[1], cv2.INTER_LANCZOS4, cv2.BORDER_CONSTANT, 0)
# Crop the image
Left_nice = Left_nice[yL:yL+hL, xL:xL+wL]
Right_nice = Right_nice[yR:yR+hR, xR:xR+wR]
# Show both Stereo Images
cv2.imshow('Right Stereo',cv2.resize(Right_nice,(640,480),interpolation = cv2.INTER_AREA))
cv2.imshow('Left Stereo',cv2.resize(Left_nice,(640,480),interpolation = cv2.INTER_AREA))
cv2.waitKey(1)