【发布时间】:2019-12-27 20:13:27
【问题描述】:
我有代码说:
def averaged_slope_intercept(mage, lines, line=None):
left_fit = []
right_fit = []
x1, y1, x2, y2 = line.reshape(4)
for line in lines:
line.reshape(4)
x1, y1, x2, y2 = line.reshape(4)
parameters = np.polyfit((x1,x2),(y1,y2), 1)
print(parameters)
slope = parameters[0]
intercept = parameters[1]
if slope < 0:
left_fit.append((slope, intercept))
else:
right_fit.append((slope, intercept))
print(left_fit)
print(right_fit)
left_fit_avarage = np.average(left_fit, axis=0)
right_fit_avarage = np.average(right_fit, axis=0)
print(left_fit_avarage, "left")
print(right_fit_avarage, "right")
left_line = make_coordinates(mage, left_fit_average)
right_line = make_coordinates(mage, right_fit_average)
return np.array([left_line, right_line])
但我不断收到此错误: : 没有足够的值来解包(预期 4,得到 1) 在线: x1, y1, x2, y2 = line.reshape(4)
【问题讨论】:
-
reshape()返回一个numpy数组,而不是 4 个值。 -
可以调整行为
x1, y1, x2, y2 = *line.reshape(4),解构数组赋值。 -
line或lines看起来像什么?它具有reshape方法这一事实意味着它是一个numpy 数组,但dtype和shape是什么?