Python 3.x 有时程序工作正常,有时显示高度、宽度、层=img.shape AttributeError:';非类型';对象没有属性';形状'; 程序有时工作,有时出错*
专家解释说 如果无法读取图像(由于缺少文件、权限不正确、格式不受支持或无效),函数将返回空矩阵 调用Python 3.x 有时程序工作正常,有时显示高度、宽度、层=img.shape AttributeError:';非类型';对象没有属性';形状'; 程序有时工作,有时出错*,python-3.x,opencv,image-processing,Python 3.x,Opencv,Image Processing,专家解释说 如果无法读取图像(由于缺少文件、权限不正确、格式不受支持或无效),函数将返回空矩阵 调用.imread()后,您将立即检查此类故障: img_array = [] for filename in glob.glob('/home/adnan/Downloads/*.png'): img = cv2.imread(filename) print(img) height, width, layers = img.shape size = (width,he
.imread()
后,您将立即检查此类故障:
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()
我找到了解决办法
实际上问题来自imread()函数
我只是简单地更新了libpng库,之后它就开始工作了,而不是把链接放在图片上或发布图片。请复制粘贴准确的代码,以便其他人可以试用您的代码并更好地帮助您。要么图像为空,即有0字节,要么图像应为灰度。如果我尝试打印失败(img),它正在打印矩阵,但上次显示相同的错误
if img is None:
continue