From my understanding, we can use the following formula to obtain the real distance from depth map. The focal length of a pi camera in terms of pixel is 2571.4, while the distance betweeen my two cameras is 0.065m. so using this formula based on the triangulation method,
Distance = (focal length * distance between 2 camera)/disparity map.
I also generated a disparity map with the following code:
stereo = cv2.StereoBM_create(numDisparities=48, blockSize=25)
disparity = steeo.compute(rectified_pair[0], rectified_pair[1])
norm_image = cv2.normalize(disparity, None, alpha = 0, beta =1, norm_type=cv2.NORM_MINMAX, dtype=cv.CV_32F)
f = 2571.4
b = 0.065
distance = (b*f)/disparity
cv2.imshow(norm_image)
I realize my 'disparity' image range starts from -16. I am getting negative values for both set of codes and I am unsure if this is a correct method to calculate distance. Also, I have calibrated my cameras. Thank you!