你好我正在使用OpenCV的Raspberry Pi。我想尝试在链接http://www.pyimagesearch.com/2015/09/14/ball-tracking-with-opencv/中进行球跟踪的教程
但是当我编译它时,我得到一个错误:'NoneType'对象没有属性'shape'。
我该怎么办?
这意味着某个应该返回图像的函数只返回None,因此没有shape属性。尝试“print img”来检查您的图像是否为None或实际的numpy对象。
我今天遇到了同样的问题,请检查cybseccrypt提到的图像路径。在imread之后,尝试打印图像并查看。如果获得值,则表示文件已打开。
码:
img_src = cv2.imread('/home/deepak/python-workout/box2.jpg',0)
print img_src
希望这可以帮助!
您可能会收到错误,因为您的视频路径可能在某种程度上是错误的。确保您的路径完全正确。
尝试处理错误,它是OpenCV给出的属性错误
try:
img.shape
print("checked for shape".format(img.shape))
except AttributeError:
print("shape not found")
#code to move to next frame
这是因为图像路径错误或您编写的图像名称不正确。
怎么检查?首先尝试使用print(img)打印图像,如果它打印“无”,这意味着你给出了错误的图像路径,正确的路径,然后再试一次。
我只是遇到同样的问题。我通过更新最新版本的OpenCV来解决它。它适合我。希望你也可以。
希望这有助于任何面临同样问题的人
要确切知道发生了什么,因为正在运行的程序没有将其作为行号错误提及
'NoneType' object has no attribute 'shape'
确保在加载assert
后添加image/frame
对于图像
image = cv2.imread('myimage.png')
assert not isinstance(image,type(None)), 'image not found'
对于视频
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'
帮我解决了类似的问题,用长脚本