Python 3.x 为什么我得到';非类型';对象不可下标错误?

Python 3.x 为什么我得到';非类型';对象不可下标错误?,python-3.x,opencv,matplotlib,computer-vision,Python 3.x,Opencv,Matplotlib,Computer Vision,我在下面的代码片段中得到了这个错误。我正在计算图像的嵌入 ----> 4 img = load_image(m.image_path()) 5 img = align_image(img) 6 # scale RGB values to interval [0,1] <ipython-input-14-23aefaa58a32> in load_image(path) 12 # in BGR order. So

我在下面的代码片段中得到了这个错误。我正在计算图像的嵌入

----> 4     img = load_image(m.image_path())
      5     img = align_image(img)
      6     # scale RGB values to interval [0,1]

<ipython-input-14-23aefaa58a32> in load_image(path)
     12     # in BGR order. So we need to reverse them
     13     #destRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
---> 14     return img[...,::-1]
     15     #return destRGB
     16 

TypeError: 'NoneType' object is not subscriptable
--->4 img=load\u image(m.image\u path())
5 img=对齐图像(img)
6#将RGB值缩放到间隔[0,1]
在加载_映像(路径)中
12#按BGR顺序。所以我们需要扭转这种局面
13#destgb=cv2.cvt颜色(img,cv2.COLOR_BGR2RGB)
--->14返回img[…,:-1]
15#返回0 GB
16
TypeError:“非类型”对象不可下标

您的代码看起来不错,但当目录中有多个文件格式时,必须确保使用条件检查

在您的例子中,由于图像文件
.jpg
中有一个“.db”文件,python抛出了一个可订阅错误

如注释中所述,在执行所需操作之前,您可以通过以下方式使用条件检查:

if file.endswith('.jpg'):
    #--- carry out your operation here
else:
    print(file)  #-- print the file not in the desired format

你确定路径是正确的吗?是的。当我将其用于面数据段时,其工作jc_orig=load_image(元数据[5]。image_path())在继续之前,请检查
img
是否为空@karanpurohittit不是空的。很难说,因为你没有告诉我们如何获得这些路径。请