问题描述
我正在尝试在 python 中进行基本的颜色转换,但是我似乎无法克服以下错误.我重新安装了 python、opencv,并在 python 3.4.3(最新)和 python 2.7(在我的 Mac 上)上都试过了.
I am trying to do a basic colour conversion in python however I can't seem to get past the below error. I have re-installed python, opencv and tried on both python 3.4.3 (latest) and python 2.7 (which is on my Mac).
我使用 python 的包管理器 opencv-python 安装了 opencv.
I installed opencv using python's package manager opencv-python.
这是失败的代码:
frame = cv2.imread('frames/frame%d.tiff' % count)
frame_HSV= cv2.cvtColor(frame,cv2.COLOR_RGB2HSV)
这是错误信息:
cv2.error: OpenCV(3.4.3) /Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
推荐答案
发生此错误是因为图像未正确加载.所以前一行 cv2.imread
有问题.我的建议是:
This error happened because the image didn't load properly. So you have a problem with the previous line cv2.imread
. My suggestion is :
检查图像是否存在于您提供的路径中
check if the image exists in the path you give
检查计数变量是否有有效数字
check if the count variable has a valid number
这篇关于imread 返回 None,违反了函数“cvtColor"错误中的断言 !_src.empty()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!