title: Calculate depth disparity map using opencv
body: <p>I have trouble calculating depth from disparity map using opencv. I know that the distance in two stereo images is calculated with <code>z = (baseline * focal) / (disparity * p)</code> but I can not figure out how to calculate the disparity using the map. The code I use if the following, providing me with a disparity map of the two images. </p>
  
  <pre><code>import numpy as np
  import cv2
  
  # Load the left and right images in gray scale
  imgLeft = cv2.imread('logga.png', 0)
  imgRight = cv2.imread('logga1.png', 0)
  
  # Initialize the stereo block matching object 
  stereo = cv2.StereoBM_create(numDisparities=16, blockSize=5)
  
  # Compute the disparity image
  disparity = stereo.compute(imgLeft, imgRight)
  
  # Normalize the image for representation
  min = disparity.min()
  max = disparity.max()
  disparity = np.uint8(6400 * (disparity - min) / (max - min))
  
  
  
  # Display the result
  cv2.imshow('disparittet', np.hstack((imgLeft, imgRight, disparity)))
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  </code></pre>