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?
you have to check, if imread() actually read something. (i bet a beer, not so.)
python users almost never do (don't they get murphy's law, or what ?), thus all those interesting problems ;)
Hi @berak yes, I checked and it is reading the images fine - the error remains
default is 21 see here i somehow do not believe you ... ;) (and i can't reproduce it with proper images)
I know it is reading the images as I can get the details of the images and even show them.
blockSize == SADWindowSize , but no idea now