我提取特征并将它们作为向量传递给训练分类器。我收到了这个错误:
unsupported operand type(s) for -: 'list' and 'int'`
我理解错误,但我似乎不知道我做错了什么,有什么帮助?
def featurestest (img):
# corners
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
corners = cv2.goodFeaturesToTrack(gray, 25, 0.01, 10)
corners = np.int0(corners)
for i in corners:
x, y = i.ravel()
cv2.circle(img, (x, y), 3, 255, -1)
# edges
edges = cv2.Canny(gray, 10, 100, apertureSize=3)
minLineLength = 50
lines = cv2.HoughLinesP(image=edges, rho=1, theta=np.pi / 180, threshold=100, lines=np.array([]),
minLineLength=minLineLength, maxLineGap=80)
a, b, c = lines.shape
for i in range(a):
cv2.line(gray, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 3, cv2.LINE_AA)
# print(lines, edges)
# aspect ratio
ar = 1.0 * float(img.shape[1] / img.shape[0])
# skew and kurtosis
skew = scipy.stats.skew(img)
kurt = scipy.stats.kurtosis(img)
for i in range(0, img.shape[0]):
for j in range(0, img.shape[1]):
vector_val = np.arange([lines,edges, ar, x, y, skew,kurt])
return_raf= (vector_val)
return return_raf
答案 0 :(得分:1)
该行
vector_val = np.arange([lines, edges, ar, x, y, skew, kurt])
错了。我不确定你要做什么,但np.arange
需要启动,停止和步长,并返回该范围内均匀间隔数字的数组。你给它一个列表作为它的第一个参数,这是一个类型错误。
出现实际的错误消息,因为np.arange
内部正在通过执行(stop - start) / step
之类的操作来计算其范围。在这种情况下,stop
是您提供的列表,start
默认为0.所以它正在执行[lines, edges, ar, x, y, skew, kurt] - 0
,这会在此处引发确切的TypeError
。< / p>