OpenCV(4.6.0) imread 读取空 问题解决方法小记
详情如下:
D:\ProgramData\Anaconda3\python.exe F:/.../image_q...ity.py
浙A..._207
C:\Users\kngin\...\浙A0..._207.jpeg======================
[ WARN:0@0.363] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('C:\Users\kngin\...\浙A0..._207.jpeg'): can't open/read file: check file path/integrity
Traceback (most recent call last):
File "F:/.../image_q...ity.py", line 15, in <module>
resultScharr[imageName]=get_picture_scharr(os.path.join(img_folder, txt_file[index]))
File "F:\...\Cle...gorithm.py", line 14, in get_picture_scharr
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
Process finished with exit code 1
解决方案
1. 安装imageio模块文章来源:https://www.toymoban.com/news/detail-839432.html
# 安装imageio模块,执行其一即可
pip install imageio -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
conda install imageio
2. 代码修改文章来源地址https://www.toymoban.com/news/detail-839432.html
# 原代码
import cv2
img = cv2.imread(path)
# 替换后代码,代码可正常运行
import imageio
img = imageio.imread(path)
材料参考
- cv2.imread获取图片为空
- 2022-11-03关于cv2.imread()读取图片返回None的原因及解决办法
到了这里,关于cv2.error: OpenCV(4.6.0) (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor‘的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!