【发布时间】:2020-02-03 22:14:35
【问题描述】:
我正在为中轴变换编写一些代码并得到一些类型错误 对于我的数组。
import cv2
import numpy as np
img = cv2.imread('cvSmall.png',0)
print(img.shape)
thresh = 230
maxValue = 255
th, dst = cv2.threshold(img, thresh, maxValue, cv2.THRESH_BINARY_INV);
cv2.imshow('image',dst)
fZero = np.zeros((len(dst),len(dst[0])))
for y in range(0,len(dst)-1):
for x in range(0,len(dst[0])-1):
if dst[y][x] == 255:
fZero[y][x] = 1
print(fZero.shape)
global currentF
global nextF
currentF = np.zeros((len(dst),len(dst[0])))
currentF = fZero.copy
nextF = np.zeros((len(dst),len(dst[0])))
def iterationFunction():
for y in range(1,len(dst)-2):
for x in range(1,len(dst[0])-2):
nextF[y][x] += fZero[y][x]
nextF[y][x] += min((currentF[y-1][x]), (currentF[y+1][x]), (currentF[y][x-1]),(currentF[y][x+1]))
#Error in this line
print (nextF)
iterationFunction()
这是我得到的错误:
第 37 行,在迭代函数中 nextF[y][x] += min((currentF[y-1][x]), (currentF[y+1][x]), (currentF[y][x-1]),(currentF[ y][x+1]))
类型错误: 'builtin_function_or_method' 对象不可下标
【问题讨论】:
标签: python arrays numpy opencv typeerror