【问题标题】:Why is the Python OpenCV code showing the error 'NoneType' object has no attribute '__getitem__'? [duplicate]为什么 Python OpenCV 代码显示错误“NoneType”对象没有属性“__getitem__”? [复制]
【发布时间】:2019-03-18 16:37:26
【问题描述】:

我正在使用 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】:

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

【讨论】:

    猜你喜欢
    • 2017-08-17
    • 2018-04-13
    • 2013-04-15
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 2017-01-08
    • 1970-01-01
    • 2012-12-04
    相关资源
    最近更新 更多