python - - 不支持的操作数类型:“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
解决方案
线
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
问题。
推荐阅读
- rest - Huobi REST API - 签名请求 - 验证失败
- matlab - MATLAB - 编译 jpeg_read.c 以创建 mexmaci64 文件时出错
- python - 如何获取不在模式 grep 中的所有内容
- javascript - React / ES6 Onscroll功能未在Y方向触发
- excel - 查找今天之后与日期编号和工作日匹配的第一个日期
- html - 当我使用 *ngFor 时,如何保存单选按钮单击?
- c# - 需要帮助将 winform 迁移到 net 5
- yii2 - Yii2:将行为附加到每个控制器
- java - Spring HttpClientErrorException 和 RestClientException 获取请求 URL
- javascript - 对代码进行更改后清理缓存的解决方案?