logo

openmv进行十字路口检测,判断两直线是否相交

2024-07-12 17:23
Q
gtf5

为什么会提示TypeError: object ‘int’ isn’t a tuple or list

提示错误的时候光标定位在img = sensor.snapshot().binary(line_threshold)

import sensor, image

# 初始化摄像头
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

line_threshold = (30, 100)

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
    # 输出是否检测到十字
    print("Cross detected: ", cross_detected)
Q
gtf5

准确的说光标定位在img = sensor.snapshot().binary(line_threshold)的后面

2024-07-12 18:59
I
网红小智智 星瞳科技

12行,改为:img = sensor.snapshot().binary([line_threshold])