首页 > 解决方案 > - 不支持的操作数类型:“list”和“int”

问题描述

我正在提取特征并将它们作为向量传递给训练分类器。我收到了这个错误:

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

标签: pythonnumpyopencvvectorcv2

解决方案


线

vector_val = np.arange([lines, edges, ar, x, y, skew, kurt])

是错的。我不确定您要做什么,但np.arange需要开始、停止和步长,并返回该范围内的均匀间隔数字数组。你给它一个列表作为它的第一个参数,这是一个类型错误。

出现实际错误消息是因为np.arange内部正在通过执行类似的操作来计算其范围(stop - start) / stepstop在这种情况下是您给它的列表,start默认为 0。所以它在做[lines, edges, ar, x, y, skew, kurt] - 0,这在这里提出了确切的TypeError问题。


推荐阅读