logo

只想打印其中一条直线的x1分量(比如打印第一个直线的x1),如何加代码?

2023-08-18 11:31
V
s2tb

识别直线使用line.x1()的时候屏幕出现两条或以上的直线,但我只想打印其中一条直线的x1分量(比如打印第一个直线的x1),如何加代码?

2023-08-19 01:30
I
网红小智智 星瞳科技
lines = img.findlines()
if lines:
    line = lines[0]
    print(line.x1())
2023-08-19 09:07
V
s2tb

报错'Image' object has no attribute 'findlines',代码全部发出来了

enable_lens_corr = False # turn on for straighter lines...打开以获得更直的线条…
import sensor, image, time
from pyb import Pin, Timer

sensor.reset()
sensor.set_pixformat(sensor.RGB565) #灰度更快
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
light = Timer(2, freq=50000).channel(1, Timer.PWM, pin=Pin("P6"))
light.pulse_width_percent(50) # 控制亮度 0~100
clock = time.clock()

min_degree = 0
max_degree = 179

while(True):
    clock.tick()
    img = sensor.snapshot()
    time.sleep_ms(1)
    if enable_lens_corr: img.lens_corr(1.8) # for 2.8mm lens...
    for l in img.find_lines(threshold = 1000, theta_margin = 25, rho_margin = 25):
        if (min_degree <= l.theta()) and (l.theta() <= max_degree):
            img.draw_line(l.line(), color = (255, 0, 0))
            lines = img.findlines()
            if lines:
                line = l[0]
                print(line.x1())
           
    print("FPS %f" % clock.fps())
2023-08-21 12:41
I
网红小智智 星瞳科技
enable_lens_corr = False # turn on for straighter lines...打开以获得更直的线条…
import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565) #灰度更快
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

min_degree = 0
max_degree = 179

while(True):
    clock.tick()
    img = sensor.snapshot()
    if enable_lens_corr: img.lens_corr(1.8) # for 2.8mm lens...
    
    lines = img.find_lines(threshold = 1000, theta_margin = 25, rho_margin = 25)
    if lines:
        line = lines[0]
        print(line.x1())