openmv的P9引脚外接了一个LED
-
我在P9引脚外接了一个LED灯,我想让openmv检测到矩形的时候P9输出高电平点亮LED,反之熄灭,但是它报错了
import sensor, image, time from pyb import UART,LED import pyb sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) # 灰度更快(160x120 max on OpenMV-M7) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() p = pyb.Pin("P9",pyb.Pin.OUT_PP) tuple([p.high(),p.low()]) #p.high() #p.low() LED(1).on() LED(2).on() LED(3).on() while(True): clock.tick() img = sensor.snapshot() jx=img.find_rects(threshold = 15000) # 下面的`threshold`应设置为足够高的值,以滤除在图像中检测到的具有 # 低边缘幅度的噪声矩形。最适用与背景形成鲜明对比的矩形。 for r in img.find_rects(threshold = 15000): if jx: p=tuple([p.high()]) else: p=tuple([p.low()]) img.draw_rectangle(r.rect(), color = (255, 0, 0)) cx = r.x() + (r.w() // 2) cy = r.y() + (r.h() // 2) img.draw_line((80,60,cx,cy), color=(127)) img.draw_cross(cx ,cy) img.draw_cross(80 ,60) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) print(cx,cy) print("FPS %f" % clock.fps())
下面是它的报错
怎么解决
-
25行和27行,p怎么变成tuple了?
-
我直接写P=p.high()它就报错,说我tuple缺少'high'
-
大概改了一下代码:
import sensor, image, time from pyb import UART,LED import pyb sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) # 灰度更快(160x120 max on OpenMV-M7) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() p = pyb.Pin("P9",pyb.Pin.OUT_PP) #p.high() #p.low() LED(1).on() LED(2).on() LED(3).on() while(True): clock.tick() img = sensor.snapshot() rects=img.find_rects(threshold = 15000) if rects: p.value(1) else: p.value(0) for r in rects: img.draw_rectangle(r.rect(), color = (255, 0, 0)) cx = r.x() + (r.w() // 2) cy = r.y() + (r.h() // 2) img.draw_line((80,60,cx,cy), color=(127)) img.draw_cross(cx ,cy) img.draw_cross(80 ,60) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) print(cx,cy) print("FPS %f" % clock.fps())