为什么显示错误'NoneType'对象的Python OpenCV代码没有属性'__getitem__'? [重复]

问题描述 投票:-1回答:1

这个问题在这里已有答案:

我正在使用Python代码在Raspberry PI中使用OpenCV。我的代码如下所示。

    import numpy as np
    import cv2

    img = cv2.imread('/home/pi/Project_pi/messi.jpg',0)
    print img[0,0]

错误如下:

Traceback (most recent call last):
  File "Gayathri.py", line 5, in <module>
    print img[0,0]
TypeError: 'NoneType' object has no attribute '__getitem__'
python opencv raspberry-pi webcam
1个回答
0
投票

如果我是你,我会检查文件位置是否正确,因为如果不是OpenCV没有返回错误或警告,而是生成img None。类的__getitem__方法通常用于索引该类的对象,显然您无法索引None对象。

© www.soinside.com 2019 - 2024. All rights reserved.