美文网首页
opencv图像复原后显示报错且程序崩了error: OpenC

opencv图像复原后显示报错且程序崩了error: OpenC

作者: 丙吉 | 来源:发表于2023-06-13 16:53 被阅读0次

问题将RGB三个数据组合后显示不出图像,且程序崩溃,报错如下:

error: OpenCV(4.7.0) D:/a/opencv-python/opencv-python/opencv/modules/highgui/src/precomp.hpp:155: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'

原因:数据类型不对,需改为np.uint8型的或np.float型

1686732412055.png

代码:

# 修改数据类型
for col in ['r', 'g', 'b']:
    exl[col] = exl[col].apply(lambda x:np.uint8(x))

# 图像复原
exl_fy = cv.merge((np.array(exl['b']).reshape(136,136),np.array(exl['g']).reshape(136,136),np.array(exl['r']).reshape(136,136)))

# 图像的显示
cv.imshow('exl_fy', exl_fy)
# 等待时间,毫秒级,0表示任意键终止
cv.waitKey(0)
cv.destroyAllWindows()
显示成功
1686732714173.png

参考:

error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow - DylanYeung - 博客园 (cnblogs.com)

相关文章

网友评论

      本文标题:opencv图像复原后显示报错且程序崩了error: OpenC

      本文链接:https://www.haomeiwen.com/subject/mwicydtx.html