Ask Your Question

Revision history [back]

How to resolve a SADWindowSize error?

I have Python version 3.6 and OpenCV version 3.4.0

I am currently working through the OpenCV (Python) tutorial Depth Map from Stereo Images. I get how the code works (below):

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
imgL = cv.imread('tsukuba_l.png',0)
imgR = cv.imread('tsukuba_r.png',0)
stereo = cv.StereoBM_create(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()

This is similar to the previous StackOverflow question Python/OpenCV: Why is cv2.StereoBM not working in this case?, however, unlike that question, when I get to the line:

disparity = stereo.compute(imgL,imgR)

I encounter the error:

error Traceback (most recent call last) <ipython-input-26-5ea252da384c> in <module>() ----> 1 disp = stereo.compute(imgl, imgr)

error: C:\projects\opencv-python\opencv\modules\calib3d\src\stereobm.cpp:1090: error: (-211) SADWindowSize must be odd, be within 5..255 and be not larger than image width or height in function cv::StereoBMImpl::compute

and can go no further. I checked and confirmed that the images are of the exact save size. I do understand what the SADWindowSize does (Sum of Absolute Differences), but do not know where and how to change this parameter to fix the error. How can I fix the SADWindowSize to fix this error?

How to resolve a SADWindowSize error?

I have Python version 3.6 and OpenCV version 3.4.0

I am currently working through the OpenCV (Python) tutorial Depth Map from Stereo Images. I get how the code works (below):

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
imgL = cv.imread('tsukuba_l.png',0)
imgR = cv.imread('tsukuba_r.png',0)
stereo = cv.StereoBM_create(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()

This is similar to the previous StackOverflow question Python/OpenCV: Why is cv2.StereoBM not working in this case?, however, unlike that question, when I get to the line:

disparity = stereo.compute(imgL,imgR)

I encounter the error:

error Traceback (most recent call last) <ipython-input-26-5ea252da384c> in <module>() ----> 1 disp = stereo.compute(imgl, imgr)

error: C:\projects\opencv-python\opencv\modules\calib3d\src\stereobm.cpp:1090: error: (-211) SADWindowSize must be odd, be within 5..255 and be not larger than image width or height in function cv::StereoBMImpl::compute

and can go no further. I checked and confirmed that the images are of the exact save same size. I do understand what the SADWindowSize does (Sum of Absolute Differences), but do not know where and how to change this parameter to fix the error. How can I fix the SADWindowSize to fix this error?

How to resolve a SADWindowSize error?

I have Python version 3.6 and OpenCV version 3.4.0

I am currently working through the OpenCV (Python) tutorial Depth Map from Stereo Images. I get how the code works (below):

import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
imgL = cv.imread('tsukuba_l.png',0)
imgR = cv.imread('tsukuba_r.png',0)
stereo = cv.StereoBM_create(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()

This is similar to the previous StackOverflow question Python/OpenCV: Why is cv2.StereoBM not working in this case?, however, unlike that question, when I get to the line:

disparity = stereo.compute(imgL,imgR)

I encounter the error:

error Traceback (most recent call last) <ipython-input-26-5ea252da384c> in <module>() ----> 1 disp = stereo.compute(imgl, imgr)

error: C:\projects\opencv-python\opencv\modules\calib3d\src\stereobm.cpp:1090: error: (-211) SADWindowSize must be odd, be within 5..255 and be not larger than image width or height in function cv::StereoBMImpl::compute

and can go no further. I checked and confirmed that the images are of the exact same size. I do understand what the SADWindowSize does (Sum of Absolute Differences), but do not know where and how to change this parameter to fix the error. How can I fix the SADWindowSize to fix this error?