python - 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'
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
解决方案
此断言失败的可能原因是:
- 左右图像的大小不同
- 左右图像的类型不同
- 左图的深度类型错误(需要 CV_8U)
请确保您的输入图像具有上述条件(相同大小和类型)。
推荐阅读
- autocomplete - CentOS8上的Python3.8版本是否支持自动补全格式?
- prolog - Amzi Prolog 在被调用时不会传递值
- mongodb - 猫鼬地理定位+距离查询
- typescript - 如何声明 TS 类型,它是一个对象数组,其属性的值类型为数字或字符串?
- php - PHP命名空间函数冲突
- javascript - Mongoose 在插入文档时为字段调用函数
- javascript - 以与另一个数组 JavaScript 相同的方式对一个数组进行排序
- java - Mockito @Mock 使用单个注释的多个对象
- javascript - 如何使用 Scroll Magic 插件延迟 GSAP 动画
- javascript - 未定义值时如何捕获 Json 数据错误?