OpenCV NoneType对象没有属性形状

use*_*265 4 python opencv raspberry-pi2

你好我正在使用OpenCV的Raspberry Pi.我想在链接中尝试一个关于球跟踪的教程 http://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/

但是当我编译它时,我得到一个错误:'NoneType'对象没有属性'shape'.

我该怎么办?

小智 15

这意味着某个应该返回图像的函数只返回None,因此没有shape属性.尝试"print img"来检查您的图像是否为None或实际的numpy对象.


San*_*nth 7

希望这可以帮助任何面临同样问题的人

要确切地知道发生在哪里,因为正在运行的程序没有将其作为行号错误提及

'NoneType' object has no attribute 'shape'

确保assert加载后添加image/frame

对于图像

image = cv2.imread('myimage.png')
assert not isinstance(image,type(None)), 'image not found'
Run Code Online (Sandbox Code Playgroud)

对于视频

cap = cv2.VideoCapture(0)

    while(cap.isOpened()):

        # Capture frame-by-frame
        ret, frame = cap.read()
        if ret:
            assert not isinstance(frame,type(None)), 'frame not found'
Run Code Online (Sandbox Code Playgroud)

帮助我解决了类似的问题,在一个很长的脚本中


Dee*_*k V 6

我今天也遇到了同样的问题,请检查cybseccrypt提到的图像路径。读取后,尝试打印图像并查看。如果获得值,则表示文件已打开。

码:

img_src = cv2.imread('/home/deepak/python-workout/box2.jpg',0) print img_src

希望这可以帮助!


ays*_*duz 5

您可能会收到错误消息,因为您的视频路径可能在某种程度上是错误的。确保您的路径完全正确。