title: Python/OpenCV: Computing a depth map from stereo images
body: <p>I have two stereo images that I'd like to use to compute a depth map. While I unfortunately do not know C/C++, I do know python-- so when I found <a href="https://web.archive.org/web/20150312053300/http://docs.opencv.org:80/trunk/doc/py_tutorials/py_calib3d/py_depthmap/py_depthmap.html" rel="noreferrer">this tutorial</a>, I was optimistic.</p>
  <p>Unfortunately, the tutorial appears to be somewhat out of date. It not only needs to be tweaked to run at all (renaming 'createStereoBM' to 'StereoBM') but when it does run, it doesn't give a good result, even on the example stereo-images that were used in the tutorial itself.</p>
  <p>Here's an example:</p>
  <p><img src="https://i.imgur.com/Yeuna9x.png" alt="image-left" />
  <img src="https://i.imgur.com/SuXT483.png" alt="image-right" /></p>
  <pre><code>import numpy as np
  import cv2
  from matplotlib import pyplot as plt
  
  imgL = cv2.imread('Yeuna9x.png',0)
  imgR = cv2.imread('SuXT483.png',0)
  
  stereo = cv2.StereoBM(1, 16, 15)
  disparity = stereo.compute(imgL, imgR)
  
  plt.imshow(disparity,'gray')
  plt.show()
  </code></pre>
  <p>The result:</p>
  <p><img src="https://i.imgur.com/eBwrA8C.png" alt="the result" /></p>
  <p>This looks very different from what the author of the tutorial achieves:</p>
  <p><a href="https://i.stack.imgur.com/K1mie.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/K1mie.jpg" alt="good result" /></a><br />
  <sub>(source: <a href="http://docs.opencv.org/trunk/_images/disparity_map.jpg" rel="noreferrer">opencv.org</a>)</sub></p>
  <p>Tweaking the parameters does not improve matters. All documentation I've been able to find is for the original C-version of openCV code, not the python-library-equivalent. I unfortunately haven't been able to use this to improve things.</p>
  <p>Any help would be appreciated!</p>