【问题标题】:AttributeError: 'NoneType' object has no attribute 'shape' resizing image [duplicate]AttributeError:'NoneType'对象没有属性'shape'调整图像大小[重复]
【发布时间】:2017-09-04 02:20:39
【问题描述】:

我正在尝试在 python 中调整 .tif 图像的大小。 但是当我尝试运行代码时,出现以下错误:

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

下面是sn-p的代码:

# 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)) 

有人知道怎么解决吗?

【问题讨论】:

标签: python opencv


【解决方案1】:

这是我在盒子上运行的代码:

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

所以从我的角度来看,这里没有什么可以解决的...... 除了……

把“全名”放在引号里

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 2021-05-26
    • 2019-03-10
    • 1970-01-01
    相关资源
    最近更新 更多