Beispiel #1
0
def display(page, x, y, k, save):
    global img_cnt
    global red_ch
    clock.tick()
    img = sensor.snapshot()
    if save:
        img.save("img\\img%02d.jpg"%img_cnt)
        img_cnt += 1
    global colorxy
    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)
        img.draw_rectangle(road.rect())
    blobs = img.find_blobs([blue_threshold, black_threshold], roi = roi_blue[2], x_stride=3, y_stride=6, pixels_threshold=64)
    if blobs:
        road = find_max(blobs)
        img.draw_rectangle(road.rect())
    blobs = img.find_blobs([white_threshold], roi = roi_white[chioce], pixels_threshold=9)
    if blobs:
        road = find_max(blobs)
        img.draw_rectangle(road.rect())
    print(clock.fps())
    if x == 3 and y == 0:
        img.binary([white_threshold], zero = True)
    else:
        if y < 2:
            img.binary([red_threshold[red_ch]], zero = True)
        else:
            img.binary([blue_threshold], zero = True)

    img.draw_string(0,0,  str(red_threshold[red_ch][0]),color = my_cmp(colorxy, 0),x_spacing = -2)
    img.draw_string(0,10, str(red_threshold[red_ch][1]),color = my_cmp(colorxy, 1),x_spacing = -2)
    img.draw_string(40,0, str(red_threshold[red_ch][2]),color = my_cmp(colorxy, 2),x_spacing = -2)
    img.draw_string(40,10,str(red_threshold[red_ch][3]),color = my_cmp(colorxy, 3),x_spacing = -2)
    img.draw_string(80,0, str(red_threshold[red_ch][4]),color = my_cmp(colorxy, 4),x_spacing = -2)
    img.draw_string(80,10,str(red_threshold[red_ch][5]),color = my_cmp(colorxy, 5),x_spacing = -2)
    img.draw_string(0, 20,"red",                 color = (255,255,255),    x_spacing = -2)
    img.draw_string(120,0,"wt:",                 color = my_cmp(colorxy, 6),x_spacing = -2)
    img.draw_string(140,0,str(white_threshold[0]),color = my_cmp(colorxy, 6),x_spacing = -2)
    img.draw_string(120,10,str(red_ch),            color = (255,255,0),      x_spacing = -2)

    img.draw_string(0,90, "blue",                 color = (255,255,255),    x_spacing = -2)
    img.draw_string(0,100, str(blue_threshold[0]),color = my_cmp(colorxy, 8),x_spacing = -2)
    img.draw_string(0,110, str(blue_threshold[1]),color = my_cmp(colorxy, 9),x_spacing = -2)
    img.draw_string(40,100,str(blue_threshold[2]),color = my_cmp(colorxy, 10),x_spacing = -2)
    img.draw_string(40,110,str(blue_threshold[3]),color = my_cmp(colorxy, 11),x_spacing = -2)
    img.draw_string(80,100,str(blue_threshold[4]),color = my_cmp(colorxy, 12),x_spacing = -2)
    img.draw_string(80,110,str(blue_threshold[5]),color = my_cmp(colorxy, 13),x_spacing = -2)
    img.draw_string(120,110, "blk",               color = my_cmp(colorxy, 14),x_spacing = -2)
    img.draw_string(140,110,str(black_threshold[1]),color = my_cmp(colorxy, 14),x_spacing = -2)

    if page == 0:
        my_ips.display_QQVGA(0, 0, img)
        if x == 0:
            if y == 0:
                red_threshold[red_ch][0] += k
                colorxy = 0
            elif y == 1:
                red_threshold[red_ch][1] += k
                colorxy = 1
            elif y == 2:
                blue_threshold[0] += k
                colorxy = 8+0
            elif y == 3:
                blue_threshold[1] += k
                colorxy = 8+1
        elif x == 1:
            if y == 0:
                red_threshold[red_ch][2] += k
                colorxy = 2
            elif y == 1:
                red_threshold[red_ch][3] += k
                colorxy = 3
            elif y == 2:
                blue_threshold[2] += k
                colorxy = 8+2
            elif y == 3:
                blue_threshold[3] += k
                colorxy = 8+3
        elif x == 2:
            if y == 0:
                red_threshold[red_ch][4] += k
                colorxy = 4
            elif y == 1:
                red_threshold[red_ch][5] += k
                colorxy = 5
            elif y == 2:
                blue_threshold[4] += k
                colorxy = 8+4
            elif y == 3:
                blue_threshold[5] += k
                colorxy = 8+5
        elif x == 3:
            if y == 0:
                white_threshold[0] += k
                colorxy = 6
            elif y == 1:
                red_ch += k
                colorxy = 7
            elif y == 3:
                black_threshold[1] += k
                colorxy = 8+6
Beispiel #2
0
def display(page, x, y, k, save):
    global img_cnt
    img = sensor.snapshot()
    if save:
        img.save("img\\img%02d.jpg" % img_cnt)
        img_cnt += 1
    global colorxy
    blobs = img.find_blobs([red_threshold],
                           roi=(47, 25, 103, 70),
                           x_stride=10,
                           y_stride=5,
                           pixels_threshold=200)
    if blobs:
        obstacle = find_max(blobs)
        img.draw_rectangle(obstacle.rect())

    blobs = img.find_blobs([blue_threshold, black_threshold],
                           roi=roiblue[0],
                           x_stride=6,
                           y_stride=3,
                           pixels_threshold=64)
    if blobs:
        road = find_max(blobs)
        img.draw_rectangle(road.rect())
    blobs = img.find_blobs([blue_threshold, black_threshold],
                           roi=roiblue[2],
                           x_stride=6,
                           y_stride=3,
                           pixels_threshold=36)
    if blobs:
        road = find_max(blobs)
        img.draw_rectangle(road.rect())

    if y < 2:
        img.binary([red_threshold], zero=True)
    else:
        img.binary([blue_threshold], zero=True)

    img.draw_string(0,
                    0,
                    str(red_threshold[0]),
                    color=my_cmp(colorxy, 0),
                    x_spacing=-2)
    img.draw_string(0,
                    10,
                    str(red_threshold[1]),
                    color=my_cmp(colorxy, 1),
                    x_spacing=-2)
    img.draw_string(40,
                    0,
                    str(red_threshold[2]),
                    color=my_cmp(colorxy, 2),
                    x_spacing=-2)
    img.draw_string(40,
                    10,
                    str(red_threshold[3]),
                    color=my_cmp(colorxy, 3),
                    x_spacing=-2)
    img.draw_string(80,
                    0,
                    str(red_threshold[4]),
                    color=my_cmp(colorxy, 4),
                    x_spacing=-2)
    img.draw_string(80,
                    10,
                    str(red_threshold[5]),
                    color=my_cmp(colorxy, 5),
                    x_spacing=-2)

    img.draw_string(0,
                    100,
                    str(blue_threshold[0]),
                    color=my_cmp(colorxy, 6),
                    x_spacing=-2)
    img.draw_string(0,
                    110,
                    str(blue_threshold[1]),
                    color=my_cmp(colorxy, 7),
                    x_spacing=-2)
    img.draw_string(40,
                    100,
                    str(blue_threshold[2]),
                    color=my_cmp(colorxy, 8),
                    x_spacing=-2)
    img.draw_string(40,
                    110,
                    str(blue_threshold[3]),
                    color=my_cmp(colorxy, 9),
                    x_spacing=-2)
    img.draw_string(80,
                    100,
                    str(blue_threshold[4]),
                    color=my_cmp(colorxy, 10),
                    x_spacing=-2)
    img.draw_string(80,
                    110,
                    str(blue_threshold[5]),
                    color=my_cmp(colorxy, 11),
                    x_spacing=-2)
    img.draw_string(120,
                    100,
                    str(black_threshold[0]),
                    color=my_cmp(colorxy, 12),
                    x_spacing=-2)
    img.draw_string(120,
                    110,
                    str(black_threshold[1]),
                    color=my_cmp(colorxy, 13),
                    x_spacing=-2)

    if page == 0:
        my_ips.display_QQVGA(0, 0, img)
        if x == 0:
            if y == 0:
                red_threshold[0] += k
                colorxy = 0
            elif y == 1:
                red_threshold[1] += k
                colorxy = 1
            elif y == 2:
                blue_threshold[0] += k
                colorxy = 6 + 0
            elif y == 3:
                blue_threshold[1] += k
                colorxy = 6 + 1
        elif x == 1:
            if y == 0:
                red_threshold[2] += k
                colorxy = 2
            elif y == 1:
                red_threshold[3] += k
                colorxy = 3
            elif y == 2:
                blue_threshold[2] += k
                colorxy = 6 + 2
            elif y == 3:
                blue_threshold[3] += k
                colorxy = 6 + 3
        elif x == 2:
            if y == 0:
                red_threshold[4] += k
                colorxy = 4
            elif y == 1:
                red_threshold[5] += k
                colorxy = 5
            elif y == 2:
                blue_threshold[4] += k
                colorxy = 6 + 4
            elif y == 3:
                blue_threshold[5] += k
                colorxy = 6 + 5
        elif x == 3:
            if y == 2:
                black_threshold[0] += k
                colorxy = 6 + 6
            elif y == 3:
                black_threshold[1] += k
                colorxy = 6 + 7