AttributeError: 'module' object has no attribute

I am trying to get a depth map of two stereo images. I took the code from http://docs.opencv.org/trunk/doc/py_tutorials/py_calib3d/py_depthmap/py_depthmap.html

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 introduced the Python string interpreter and wrote the following code:

 import cv2 help(cv2) 

In cv2 there is no function called createStereoBM.

Is the code incorrect in the link provided above? I am using Python 2.7.3 on Ubuntu 12.04. Is it possible that the code is for Python 3 and above?

Please, help.

+6
source share
3 answers

Use this function instead

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

You can find the documentation for this feature here.

+9
source

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

Give it a try. My version of opencv is 3.2.

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

  • import (CV2)
  • help (CV2)
+4
source

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

0
source

All Articles