Ask Your Question
0

How to resolve a SADWindowSize error?

asked 2018-03-03 21:44:15 -0600

Professor_X gravatar image

updated 2018-03-04 00:36:19 -0600

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?

edit retag flag offensive close merge delete

Comments

1

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 ;)

berak gravatar imageberak ( 2018-03-04 02:13:05 -0600 )edit

Hi @berak yes, I checked and it is reading the images fine - the error remains

Professor_X gravatar imageProfessor_X ( 2018-03-04 02:28:36 -0600 )edit
1

default is 21 see here i somehow do not believe you ... ;) (and i can't reproduce it with proper images)

berak gravatar imageberak ( 2018-03-04 02:40:15 -0600 )edit
1

I know it is reading the images as I can get the details of the images and even show them.

Professor_X gravatar imageProfessor_X ( 2018-03-04 02:40:57 -0600 )edit
1

blockSize == SADWindowSize , but no idea now

berak gravatar imageberak ( 2018-03-04 02:57:16 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-03-04 03:00:26 -0600

Professor_X gravatar image

Hi @berak, I just came to the same conclusion as well - I am not sure why either, but it now works! Thank you very kindly for your help!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-03 21:44:15 -0600

Seen: 4,879 times

Last updated: Mar 04 '18