cv2.error: OpenCV(4.6.0) (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor‘

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模块

# 安装imageio模块,执行其一即可
pip install imageio -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

conda install imageio

2. 代码修改

# 原代码
import cv2
img = cv2.imread(path)


# 替换后代码,代码可正常运行
import imageio
img = imageio.imread(path)

材料参考

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xsimah

创作不易,感谢客官的打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值