import time, sensor
from pyb import UART
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)
sensor.set_windowing((120, 120))
sensor.set_auto_whitebal(True)
sensor.skip_frames(time = 20)
sensor.set_hmirror(False)
sensor.set_vflip(True)
while True:
img = sensor.snapshot()
rects = img.find_rects(threshold = 200) #ROI=(80, 60, 80, 60)
for r in rects:
rect = r.rect()
# if (rect[0] > 15 and rect[1] > 15
# and rect[2] < 60 and rect[3] < 60
# and (rect[0] + rect[2]) < 100
# and (rect[1] + rect[3]) < 100
# and (rect[0] + rect[2]) > 25
# and (rect[1] + rect[3]) > 25):
img.draw_rectangle(rect, color = (255, 0, 0))
corner = r.corners()
for point in r.corners():
img.draw_circle(point[0], point[1], 5, color = (0, 255, 0))