import sensor, image, time, pyb
from pyb import Pin
sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 灰度更快
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
led1 = pyb.LED(1)
while(True):
clock.tick()
img = sensor.snapshot()
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)
for r in img.find_rects(threshold = 10000):
img.draw_rectangle(r.rect(), color = (255, 0, 0))
print(r)
print("FPS %f" % clock.fps())
print("FPS %f" % clock.fps())
circles=img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 2, r_max = 100, r_step = 2)
rects=img.find_rects(threshold = 10000)
if circles:
led1.on()
time.sleep(3000)
led1.off()
time.sleep(100)
led1.on()
time.sleep(3000)
led1.off()
time.sleep(100)
if rects:
p_out=Pin('A8',Pin.OUT_PP)
p_out.high()