Buggy remapped image after stereo rectify

  1. Image effects
  1. Code

So, did anybody successfully obtain the remapped image after stereo rectify?

welcome.

I see darkness. do you really expect to be able to work with that data?

I am working on a similar project and have not yet obtained the results I’m looking for. You can at least get rid of the black space by cropping the image. You might also try playing around with the free scaling parameter when rectifying.

From https://docs.opencv.org/3.4/d9/d0c/group__calib3d.html: “Free scaling parameter. If it is -1 or absent, the function performs the default scaling. Otherwise, the parameter should be between 0 and 1. alpha=0 means that the rectified images are zoomed and shifted so that only valid pixels are visible (no black areas after rectification). alpha=1 means that the rectified image is decimated and shifted so that all the pixels from the original images from the cameras are retained in the rectified images (no source image pixels are lost). Any intermediate value yields an intermediate result between those two extreme cases.”

I found a solution that works for my project. Perhaps it will work for yours as well. I changed my free scaling parameter from 1 to 0.5 in the matrix optimization and it almost entirely eliminated the problem.

In your code, try changing line 58 from:
new_mtxR, roiR= cv2.getOptimalNewCameraMatrix(mtxR,distR,(wR,hR),1,(wR,hR))
to:
new_mtxR, roiR= cv2.getOptimalNewCameraMatrix(mtxR,distR,(wR,hR),0.5,(wR,hR))

See if it helps your issue. BTW, it would still be a good idea to crop the output using the ROI.

I tried 0.5 and 0.2, still problematic.

Just wonder if cv2.getOptimalNewCameraMatrix is able to handle gray images (nChannels=1, rather than 3) ?

I’m quite sure my imgL_gray is correct. Therefore, the ONLY factor causing Left_nice buggy is due to Left_Stereo_Map_x and Left_Stereo_Map_y.

		Left_nice= cv2.remap(imgL_gray,
							Left_Stereo_Map_x,
							Left_Stereo_Map_y,
							cv2.INTER_LANCZOS4,
							cv2.BORDER_CONSTANT,
							0)

So, params_py.xml in file calibrate.py is EXACTLY the same as stereo_rectify_maps.xml in file disparity2depth_calib.py, right?

why are you wondering ? getOptimalNewCameraMatrix is not dealing with image channels at all

Thank you @berak . But, why my Left_nice is NOT nice at all ?

Just a thought: there are separate free scaling parameters for both the calibration and for the stereo rectification. Did you try reducing the value on both?