只想打印其中一条直线的x1分量(比如打印第一个直线的x1),如何加代码?
-
识别直线使用line.x1()的时候屏幕出现两条或以上的直线,但我只想打印其中一条直线的x1分量(比如打印第一个直线的x1),如何加代码?
-
lines = img.findlines() if lines: line = lines[0] print(line.x1())
-
报错'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())
-
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())