Python 3.x opencv2 python3带非类型的imread
我用python3,opencv2在Ubuntu系统中编程。文件夹中有多个图像需要处理。当我使用imread时,printimg.shape显示AttributeError:“NoneType”对象没有属性“shape”。我检查了创建的图像的大小是0字节。奇怪的是,有些图像可以成功读取,但有些是非类型的。谢谢你的帮助Python 3.x opencv2 python3带非类型的imread,python-3.x,opencv,filter,imread,Python 3.x,Opencv,Filter,Imread,我用python3,opencv2在Ubuntu系统中编程。文件夹中有多个图像需要处理。当我使用imread时,printimg.shape显示AttributeError:“NoneType”对象没有属性“shape”。我检查了创建的图像的大小是0字节。奇怪的是,有些图像可以成功读取,但有些是非类型的。谢谢你的帮助 import glob as gb import cv2 import random import os import numpy as np shared_path="/hom
import glob as gb
import cv2
import random
import os
import numpy as np
shared_path="/home/train_1/"
folder_list=["HTC-1-M7"]
for j in range(len(folder_list)):
output_path=os.path.join("/home/test/",folder_list[j])
camera_path= os.path.join(shared_path,folder_list[j])
img_path = gb.glob(camera_path+"/*.jpg")
counter=1
for path in img_path:
img = cv2.imread(path)
print(img.shape)
kernel = np.array([[-1,2,-2,2,-1],[2,-6,8,-6,2],[-2,8,-12,8,-2],[2,-6,8,-6,2],[-1,2,-2,2,-1]],np.float32)/12
img = cv2.filter2D(img,-1,kernel)
这意味着在某个地方,一个应该返回图像的函数只返回None,因此它没有shape属性 尝试printimg检查您的图像是无还是实际的numpy对象。您可能会出现此错误,因为您的图像路径可能在某种程度上是错误的。确保您的路径完全正确。在读取之前检查os.path.existspath是否存在