2017-04-08 61 views
0

我想调整python中的.tif图像。 但是,当我尝试运行代码我得到以下错误:AttributeError:'NoneType'对象没有属性'形状'调整大小图像

AttributeError: 'NoneType' object has no attribute 'shape' 

下面的代码片段:

# Open de beeldfile 

image = cv2.imread(fullinname) 

# Bepaal afmetingen en aantal kleurkanalen 

width = image.shape[1] 

height = image.shape[0] 

colors = image.shape[2] 

print ("{} pixels breed".format(width)) 
print ("{} pixels hoog".format(height)) 
print ("{} kleur kanalen".format(colors)) 

img = cv2.resize(image, (512, 512)) 

有谁知道如何解决这个问题?

+0

不,只有1个cv2.imread在我的文件 –

+1

如果没有发布5个答案没有解决您的问题,那么也许[任何这些](https://www.google.ca/search?client = safari&rls = en&q = python + cv2.imread +返回+ none&ie = UTF-8&oe = UTF-8&gfe_rd = cr&ei = NF7pWLCjNMuC8Qe4hqPACw)可以提供帮助吗?这是一个相当普遍的问题,我相信一些研究会产生一个解决方案。 (参见[Stack Overflow用户需要多少研究工作?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) ) –

+0

你可以调试'fullinname'吗? – ZdaR

回答

0

在这里,我是在我的机器上运行的代码:

import cv2 
# Open de beeldfile 
image = cv2.imread("/fullPathImageName.jpg") 
# Bepaal afmetingen en aantal kleurkanalen 

width = image.shape[1] 
height = image.shape[0] 
colors = image.shape[2] 
print ("{} pixels breed".format(width)) 
print ("{} pixels hoog".format(height)) 
print ("{} kleur kanalen".format(colors)) 

img = cv2.resize(image, (512, 512)) 

width = img.shape[1] 
height = img.shape[0] 
colors = img.shape[2] 
print ("{} pixels breed".format(width)) 
print ("{} pixels hoog".format(height)) 
print ("{} kleur kanalen".format(colors)) 

这里是它所打印:

python -u "cv2questionImageResize_Cg.py" 
816 pixels breed 
612 pixels hoog 
3 kleur kanalen 
512 pixels breed 
512 pixels hoog 
3 kleur kanalen 

所以从我的角度来看没有什么解决这里... EXCEPT ...

put "fullinname" in quotation marks

并检查文件是否存在,是否正常。