#通过检测两直线是否相交判断十字路口
import sensor, image, time
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
line_threshold = (30, 100)
noc = 0 #number of crossroad
while True:
img = sensor.snapshot().binary([line_threshold])
# 检测直线
lines = img.find_lines(threshold = 1000, theta_margin = 25, rho_margin = 25)
for line in lines:
img.draw_line(line.line(), color=127)
# 检测十字
cross_detected = False
for i in range(len(lines)):
for j in range(i+1, len(lines)):
if abs(lines[i].theta() - lines[j].theta()) < 30:
continue
intersection = lines[i].intersection(lines[j])
if intersection:
x, y = int(intersection.x()), int(intersection.y())
img.draw_cross(x, y)
cross_detected = True
noc = noc+1
# 输出是否检测到十字
print("Cross detected: ", cross_detected)
print(noc)提示AttributeError: ‘line’ object has no attribute ‘intersection’
光标位置intersection = lines[i].intersection(lines[j])
openmv里有没有类似intersection()获取交叉点的方法呢
目前没有这个函数,需要自己计算。