某些时候程序运行良好,有些时候显示高度,宽度,层= img.shape AttributeError:'NoneType'对象没有属性'shape'

时间:2019-07-07 08:00:42

标签: python-3.x opencv image-processing

img_array = []
for filename in glob.glob('/home/adnan/Downloads/*.png'):
    img = cv2.imread(filename)
    print(img)
    height, width, layers = img.shape
    size = (width,height)
    img_array.append(img)


out = cv2.VideoWriter('project.mp4',cv2.VideoWriter_fourcc(*'DIVX'), 5, size)

for i in range(len(img_array)):
    out.write(img_array[i])
out.release()
  • 程序有时会起作用,有时会出错*

2 个答案:

答案 0 :(得分:0)

docs对此进行了解释

  

如果无法读取图像(由于缺少文件,权限不正确,格式不受支持或格式无效),该函数将返回一个空矩阵

// Define an action to do when user clicks, but pass to the next line without waiting that the click event to occur document.querySelectorAll(".drum")[0].addEventListener(...); document.querySelectorAll(".drum")[1].addEventListener(...); document.querySelectorAll(".drum")[2].addEventListener(...); ... 调用之后,您将立即检查是否存在这种故障:

.imread()

答案 1 :(得分:0)

我找到了解决方案 其实问题出在imread()函数上 我只是简单地更新了libpng库,并且在那之后就可以了