9

I am trying to get the depth map of two stereo images. I have taken the code from this documentation.

I get the following error:

Traceback (most recent call last):
  File "depth.py", line 9, in <module>
    stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
AttributeError: 'module' object has no attribute 'createStereoBM'

My code is:

import numpy as np
import cv2
from matplotlib import pyplot as plt

imgL = cv2.imread('tsukuba_l.png',0)
imgR = cv2.imread('tsukuba_r.png',0)

stereo = cv2.createStereoBM(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()

I entered the Python line interpreter, and wrote the following code:

import cv2
help(cv2)

There is no function called createStereoBM in cv2.

Is the code wrong in the link provided at the top? I am using Python 2.7.3 in Ubuntu 12.04. Is it possible that the code is meant for Python 3 and above?

Please help.

vwvw
  • 372
  • 4
  • 16
Ujjwal
  • 3,088
  • 4
  • 28
  • 36
  • the code you're using is from the opencv master/3.0 branch. (and yes, you have to use cv2.createStereoBM() there instead of cv2.StereoBM() ) for looking at further examples, [use the 2.4 branch](https://github.com/Itseez/opencv/tree/2.4/samples/python2) instead . – berak Feb 11 '14 at 14:21
  • 1
    I had to use cv2.StereoBM_create() for 3.0.0-beta version of OpenCV – fdermishin Mar 25 '15 at 15:03

4 Answers4

12

cv2.StereoBM_create(numDisparities=16, blockSize=15)

Try it. My opencv version is 3.2.

If you want to find any function working in opencv, you can try this

  1. import(cv2)
  2. help(cv2)
Abhishek Raj
  • 478
  • 7
  • 17
11

Use this function instead

stereo = cv2.StereoBM(cv2.STEREO_BM_BASIC_PRESET,ndisparities=16, SADWindowSize=15)

You can find documentation for this function here

youssefhassan
  • 1,067
  • 2
  • 11
  • 17
2
import numpy as np

import cv2

from matplotlib import pyplot as plt

imgL = cv2.imread('l.png',0)

imgR = cv2.imread('r.png',0)

stereo = cv2.StereoBM_create(numDisparities=16, blockSize=15)

disparity = stereo.compute(imgL,imgR)

plt.imshow(disparity,'gray')

plt.show()  

try to use this code is your using the code from open-cv documentation

Francesco B.
  • 2,729
  • 4
  • 25
  • 37
1

You are getting the example from the trunk (aka devel) documentation. if you aren't using trunk version, try to find an example for your correct version.

pbacterio
  • 1,094
  • 6
  • 12