[英]OpenCV - Python Assertion Error : SAD algorithm - Stereo Camera Disparity Map Calculation
I want to calculate Disparity map using SAD algorithm, and when I run the code I get the error Message: return stereo.compute(left_image, right_image).astype(np.float32) / 16.0 cv2.error: OpenCV(3.4.3) C:\\projects\\opencv-python\\opencv\\modules\\calib3d\\src\\stereosgbm.cpp:2156: error: (-215:Assertion failed) left.size() == right.size() && left.type() == right.type() && left.depth() == CV_8U in function 'cv::StereoSGBMImpl::compute' 我想使用SAD算法计算视差图,并且在运行代码时收到错误消息:return geometric.compute(left_image,right_image).astype(np.float32)/ 16.0 cv2.error:OpenCV(3.4.3) C:\\ projects \\ opencv-python \\ opencv \\ modules \\ calib3d \\ src \\ stereosgbm.cpp:2156:错误:(-215:断言失败)left.size()== right.size()&& left.type() == right.type()&& left.depth()==函数'cv :: StereoSGBMImpl :: compute'中的CV_8U
My code is : 我的代码是:
left_image = cv2.imread('left.jpg')
right_image = cv2.imread('right.jpg')
def calc_disparity(left_image, right_image):
window_size = 3
min_disp = 1
num_disp = 16
stereo = cv2.StereoSGBM_create(
minDisparity=min_disp,
numDisparities=num_disp,
blockSize = 5,
# SADWindowSize=window_size,
uniquenessRatio=10,
speckleWindowSize=100,
speckleRange=32,
disp12MaxDiff=1,
P1=8*3*window_size**2,
P2=32*3*window_size**2,
# fullDP=False
)
return stereo.compute(left_image, right_image).astype(np.float32) / 16.0
Possible reasons of this assertion failure are: 此断言失败的可能原因是:
Please ensure that your input images have the above conditions (same size and type). 请确保您输入的图像具有上述条件(相同尺寸和类型)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.