这个问题在这里已有答案:
我正在使用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__'
如果我是你,我会检查文件位置是否正确,因为如果不是OpenCV没有返回错误或警告,而是生成img None
。类的__getitem__
方法通常用于索引该类的对象,显然您无法索引None
对象。