logo

出现这个错误提示,而且无法执行 def tick(timer):中的程序,也没有图像

2021-04-24 11:59
C
hgpz
请在这里粘贴代码import sensor, image, time
from pyb import Pin, Timer, LED
import utime
a =  Pin('P4', Pin.OUT_PP)
b =  Pin('P5', Pin.OUT_PP)
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 灰度更快
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

def tick(timer):
    clock.tick()
    #lens_corr(1.8)畸变矫正
    print('2')
    img = sensor.snapshot().lens_corr(1.8)
    for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 2, r_max = 100, r_step = 2):
        img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
        print(c)
        a.high()
        time.sleep_ms(200)
        a.low()
    for r in img.find_rects(threshold = 10000):
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
        for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
        print(r)
        b.high()
        time.sleep_ms(200)
        b.low()
    
    print("FPS %f" % clock.fps()) 
tim = Timer(2, freq=1)      # 使用定时器2创建定时器对象-以1Hz触发
tim.callback(tick)          # 将回调设置为tick函数
while (True):
    time.sleep_ms(1000)
    print('1')
2021-04-25 16:40
I
网红小智智 星瞳科技

中断服务函数不能使用新内存。所以不能在中断服务函数采集图像。