def main(): while True: clock.tick() pix = 0 break_road = 0 cnt1 = 0 cnt2 = 0 mode = 0 hh = 0 cc = 0 img = sensor.snapshot() t = my_uart.read() if t!= None: mode = t >> 7 offset = t & 0x7F blobs = img.find_blobs([red_threshold[red_ch]], roi = roi_red, x_stride=5, y_stride=10, pixels_threshold=200) if blobs: road = find_max(blobs) pix = road.pixels() * 255 // 3000 if pix > 255: pix = 255 if mode == 0: blobs = img.find_blobs([blue_threshold, black_threshold], roi = roi_blue[0], x_stride=3, y_stride=6, pixels_threshold=100) if blobs: road = find_max(blobs) break_road = road.pixels()*255//2500 else: blobs = img.find_blobs([blue_threshold, black_threshold], roi = roi_blue[1], x_stride=3, y_stride=6, pixels_threshold=100) if blobs: road = find_max(blobs) break_road = (road.pixels()-150)*255//3400 if break_road < 0: break_road = 0 if break_road > 255: break_road = 255 if mode == 1: blobs = img.find_blobs([white_threshold], roi = roi_white[chioce], pixels_threshold=20) if blobs: road = find_max(blobs) hh = road.h() cc = road.cy()+1 else: roi_white2[0] = int(-0.3297*offset+106.2)-3 blobs = img.find_blobs([white_threshold], roi = roi_white2, pixels_threshold=20) if blobs: road = find_max(blobs) hh = road.h() cc = road.cy()+1 my_uart.send(pix,break_road,cc,hh) if pix > 30: ledR.on() else: ledR.off() if break_road > 170: ledB.on() else: ledB.off() print(clock.fps())
def systemUI(): page = 0 Xsite = 0 Ysite = 0 global red_threshold global blue_threshold global black_threshold global white_threshold global red_ch [red_threshold, blue_threshold, black_threshold, white_threshold, red_ch] = my_file.read_parameter() my_ips.showstr(161, 0, "bR 30:127") my_ips.showstr(161, 1, " -50:50") my_ips.showstr(161, 3, "R 40:127") my_ips.showstr(161, 4, " -20:70") my_ips.showstr(161, 6, "yR 30:127") my_ips.showstr(161, 7, " 10:127") while(True): save = 0 key = my_key.get_key() if key == 3:#r if Xsite<3: Xsite += 1 elif key == 6:#l if Xsite>0: Xsite -= 1 elif key == 2:#u if Ysite>0: Ysite -= 1 elif key == 0:#d if Ysite<3: Ysite += 1 elif key == 1:#m save = 1 if key == 4: k = 1 elif key == 5: k = -1 else: k = 0 display(page, Xsite, Ysite, k, save) if my_uart.read() == 0x0F: break my_file.save_parameter(red_threshold, blue_threshold, black_threshold, white_threshold, red_ch) ledR.off() ledB.off() my_ips.spi.deinit() time.sleep(200) ledG.off()
def systemUI(): page = 0 Xsite = 0 Ysite = 0 global red_threshold global blue_threshold global black_threshold global white_threshold [red_threshold, blue_threshold, black_threshold, white_threshold] = my_file.read_parameter() while (True): save = 0 key = my_key.get_key() if key == 3: #r if Xsite < 3: Xsite += 1 elif key == 6: #l if Xsite > 0: Xsite -= 1 elif key == 2: #u if Ysite > 0: Ysite -= 1 elif key == 0: #d if Ysite < 3: Ysite += 1 elif key == 1: #m break #save = 1 if key == 4: k = 1 elif key == 5: k = -1 else: k = 0 display(page, Xsite, Ysite, k, save) if my_uart.read() == 0x0F: break my_file.save_parameter(red_threshold, blue_threshold, black_threshold, white_threshold) ledR.off() ledB.off() my_ips.spi.deinit() time.sleep(200) ledG.off()
def main(): while True: clock.tick() pix = 0 break_road = 0 img = sensor.snapshot() t = my_uart.read() if t != None: mode = t >> 7 offset = t & 0x7F blobs = img.find_blobs([red_threshold], roi=(47, 25, 87, 70), x_stride=10, y_stride=5, pixels_threshold=200) if blobs: obstacle = find_max(blobs) pix = obstacle.pixels() * 255 // 3000 if pix > 255: pix = 255 img.draw_rectangle(obstacle.rect()) blobs = img.find_blobs([blue_threshold, black_threshold], roi=(0, 21, 33, 77), x_stride=6, y_stride=3, pixels_threshold=100) if blobs: road = find_max(blobs) break_road = road.pixels() * 255 // 2500 if break_road > 255: break_road = 255 img.draw_rectangle(road.rect()) my_uart.send(pix, break_road) if pix > 30: ledR.on() else: ledR.off() if break_road > 180: ledB.on() else: ledB.off() print(clock.fps())