
能不能像巡线小车例程那样用线性回归返回直线
不过却需要返回多条line对象
我们需要两条直线对象计算偏转角度
mport sensor, image, time, math
min_degree = 0
max_degree = 179
theta_1=0
theta_2=0
i=0.00001
j=0.00001
THRESHOLD = (0,70)
# 导入 image
img = image.Image("F_example1.bmp", copy_to_fb=True).binary([THRESHOLD],invert=True)
# 添加画线的代码
for l in img.get_regression([(100,100,0,0,0,0)], robust = True):
if (min_degree <= l.theta()) and (l.theta() <= max_degree):
img.draw_line(l.line(), color = (255, 0, 0))
if l.theta()<=90 :
theta_1=theta_1+l.theta()
i=i+1
else:
theta_2=theta_2+l.theta()
j=j+1
lamb=math.atan((math.tan((theta_1/i/180)*math.pi)+math.tan((theta_2/j/180)*math.pi))/2)
lamb=lamb/math.pi*180
print(lamb)
sensor.flush()

time.sleep(100)


第十六行这个100,100,0,0,0,0是什么意思
get_regression只能返回一条直线。
你可以分成左右两边分别调用get_regression