报错1:
cv2.error: OpenCV(4.10.0) D:\a\opencv-python\opencv-python\opencv\modules\highgui\src\window.cpp:973: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
1、检查文件路径中是否存在中文,如果有,请在英文路径下打开,opencv不支持中文路径!
2、重新安装opencv
- 安装教程参考这篇文章:
http://t.csdnimg.cn/8cV3Jhttp://t.csdnimg.cn/8cV3J
报错2:
cv2.error: OpenCV(4.10.0) D:/a/opencv-python/opencv-python/opencv/modules/highgui/src/precomp.hpp:156: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'
这个错误
cv2.error: OpenCV(4.x.x) ... error: (-215:Assertion failed) src_depth != CV_16F && src_depth != CV_32S in function 'convertToShow'
通常发生在尝试使用 OpenCV 的imshow()
函数显示一个图像时,但图像的深度(数据类型)不是 OpenCV 期望的类型(通常是uint8
)。在 OpenCV 中,
imshow()
函数期望的图像数据类型是uint8
,即每个像素值的范围应该在 0 到 255 之间。如果图像是CV_16F
(16位浮点数)或CV_32S
(32位有符号整数),那么在显示之前需要将其转换为uint8
。解决方案
你可以使用
cv2.convertScaleAbs()
函数将图像数据转换为uint8
。这个函数不仅转换数据类型,还会根据需要调整像素值的范围。对于CV_16F
或CV_32S
类型的图像,它会首先将值缩放到0-255
范围内,然后转换为uint8
。
陆续更新……