我不确定这个错误是什么意思。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/johndoe/Documents/CHOP_CPR_Project/CHOP_Apr07/CPRPageClass.py", line 21, in __init__
# Determine Left Side Vertical Axis
NameError: name 'size' is not defined
我试图构建的类的相关代码:
def __init__(self, image):
# Gather initial values
self.image = image
self.size = image.size
self.pixel_array = np.asarray(self.image)
# Determine Right Side Vertical Axis
rsv_list = np.zeros(0)
for i in range(int(.2 * image.size[1]), int(.7 * image.size[1]), 5):
counter = 0
for value in self.pixel_array[i][::-1]:
if value != 255:
np.append(rsv_list, counter)
break
else:
counter += 1
self.rsva = image.size[0] - int(np.mean(rsv_list))
# Determine Left Side Vertical Axis
lsv_list = np.zeros(0)
for i in range(int(.2 * image.size[1]), int(.7 * image.size[1]), 5):
counter = 0
for value in self.pixel_array[i]:
if value != 255:
np.append(lsv_list, counter)
break
else:
counter += 1
self.lsva = int(np.mean(lsv_list))
自从我用python编码以来已经有一段时间了,所以我很生疏。我想知道是否有人可以找到解决我的错误的方法。
我试图在产生错误的终端中运行的命令:
>> image = Image.open('chop_april07_Page_01.jpg')
>> test = CPRPageClass.CPRPage(image)