### Getting Real Distance

Posted:

**Tue Mar 03, 2020 2:46 am**I have been trying to obtain the real distance of an object from a disparity map. The disparity map used is the one generated from 6_dm_video.py from the Stereopi tutorial. As far as I understand, 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)

cv2.imshow(norm_image)

.

.

f = 2571.4 b = 0.065

distance = (b*f)/disparity

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. I have calibrated my cameras.

Thank you very much.

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)

cv2.imshow(norm_image)

.

.

f = 2571.4 b = 0.065

distance = (b*f)/disparity

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. I have calibrated my cameras.

Thank you very much.