OpenCV-Python StereoBM error, thanks

I need to derive disparity map from two images. I am using Python3.7 on Win10, PyCharm, and opencv-python= The following is my code.

import cv2

image_file1 = r'cam1.jpg'
image_file2 = r'cam2.jpg'
image_left = cv2.imread(image_file1, 0)
image_right = cv2.imread(image_file2, 0)

image_left = cv2.resize(image_left, (0,0), fx=0.25, fy=0.25)
image_right = cv2.resize(image_right, (0,0), fx=0.25, fy=0.25)

stereo = cv2.StereoBM(numDisparities=16, blockSize=15)
disparity = stereo.compute(image_left,image_right)

However, I got no result, and only the information as following:
Process finished with exit code -1073741819 (0xC0000005).

No error information, and no exception information. Can anybody help me on this? Thank you very much.

The problem is from the last line, i.e., stereo.compute.

meaning you need to call StereoBM_create or StereoBM.create

when scaling images down by a power of two, consider using pyrDown (repeatedly if needed). that function applies a lowpass so there won’t be any sampling artefacts. if you stick with cv.resize, consider passing the INTER_AREA flag.

1 Like

python sample for stereo image matching and point cloud generation

1 Like

Thank you very much to all of you.