def clean_lines(lines, threshold):
slope = [(y2 - y1) / (x2 - x1) for line in lines for x1, y1, x2, y2 in line]
while len(lines) > 0:
mean = np.mean(slope)
diff = [abs(s - mean) for s in slope]
idx = np.argmax(diff)
if diff[idx] > threshold:
slope.pop(idx)
lines.pop(idx)
else:
break
程序缺少缩进,也不知道你输入的参数,主程序怎么调用的
建议你自己调试下,首先,报错信息会告诉你出错的具体行,那么你仔细观察出错的那一行代码,其中的某个索引,是否越界。