I’m working with a stereo camera that has a baseline of 30cm, each lens has a 160° FOV.
I’m trying to create a depthmap, but the created disparity map is nonsense. I have never worked with stereo vision before, so I was wondering what the possible reasons could be, so I can debug it.
I have put quite a lot of effort into calibration, but achieved only a stereo calibration RMS of around 1.3, maybe that is not good enough?
Also, I did the calibration rather close to the cameras (around 1m), and now I’m using it on object a lot further away.
Could the overexposure in the image be a problem?
Any thoughts are welcome!
This is an example image:
and it’s rectified results:
And the resulting disparity map:
The code I use:
import numpy as np
import cv2 as cv2
from matplotlib import pyplot as plt
img_width = 3280
img_height = 1232
# load calibration data
npzfile = np.load('./calibration_data/{}p/stereo_camera_calibration.npz'.format(img_height))
leftMapX = npzfile['leftMapX']
leftMapY = npzfile['leftMapY']
rightMapX = npzfile['rightMapX']
rightMapY = npzfile['rightMapY']
imageToDisp = "/test_2.jpg"
pair_img = cv2.imread(imageToDisp,0)
pair_img = cv2.resize(pair_img, (int(pair_img.shape[1]/2), int(pair_img.shape[0]/2)), interpolation = cv2.INTER_AREA)
imgLeft = pair_img [0:img_height,0:int(img_width/2)] #Y+H and X+W
imgRight = pair_img [0:img_height,int(img_width/2):img_width] #Y+H and X+W
imgL = cv2.remap(imgLeft, leftMapX, leftMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
imgR = cv2.remap(imgRight, rightMapX, rightMapY, interpolation=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT)
#resize images
image_size = (320, 240)
imgL = cv2.resize(imgL, image_size, interpolation = cv2.INTER_AREA)
imgR = cv2.resize(imgR, image_size, interpolation = cv2.INTER_AREA)
#create disparity map
stereo = cv2.StereoSGBM.create(numDisparities=16*4, blockSize=30)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity, cmap='magma')
plt.show()