Example #1
0
def main():
    is_succeeded = start_app()
    if not is_succeeded:
        return
    time.sleep(5)
    start_game()

    for _ in range(10 * 60):  # todo replace with while
        is_fail = check_failure()
        if is_fail:
            restart_game()
        else:
            current_screen = ImageGrab.grab(bbox=(0, 107, 1919, 755))
            detect_edge(current_screen)
        time.sleep(0.3)  # todo 0.1 or less

    exit_game()
def plot_test_image_and_edges():
    """
    example to plot an image and the detected edges
    """
    test_file = pth.join(".", "tests", "test_data", "10_circles_colour.gif")
    image_in = load_image(test_file)
    edges = detect_edge(image_in)
    fig, axes = plt.subplots(nrows=1, ncols=2)
    ax_orig = axes[0]
    ax_edges = axes[1]
    ax_orig.imshow(image_in)
    ax_edges.imshow(edges)
    fig.show()
def plot_edge(im,sigma=1,high_threshold=None,low_threshold=None):
    '''
    Plots original image and edge image next to each other.
    
    Arguments
    im = 2D array describing image
    sigma
    high_threshold
    low_threshold

    Function which will be made interactive.
    '''

    edges = detect_edge(im,sigma,high_threshold,low_threshold)
    
    
    fig, axes = plt.subplots(nrows=1, ncols=2)
    ax_orig = axes[0]
    ax_edges = axes[1]
    ax_orig.imshow(im)
    ax_edges.imshow(edges)
    fig.show()
def test_high_noise_img():
    im = generate_image(4, 0.5)
    edge_test = ed.detect_edge(im, sigma=6)
    profile = pp.pick_profile(edge_test) 
    ring_number = cr.count_rings(profile)                                     
    assert (ring_number == 1)
def test_medium_noise_img():
    im = generate_image(2, 0.2)
    edge_test = ed.detect_edge(im, sigma=3)    
    profile = pp.pick_profile(edge_test) 
    ring_number = cr.count_rings(profile)
    assert (ring_number == 1)
def test_clean_img():
    im = generate_image()
    edge_test = ed.detect_edge(im, sigma=2)
    profile = pp.pick_profile(edge_test) 
    ring_number = cr.count_rings(profile)
    assert (ring_number == 1)
    axes[0].imshow(z)
    axes[0].plot([x0, x1], [y0, y1], 'k-')
    axes[0].plot(x0, y0, 'go')
    axes[0].plot(x1, y1, 'ro')
    axes[0].axis('image')
    axes[0].set_title('Binary edges image')
    
    axes[1].plot(profile,'ko-')
    axes[1].plot(0,profile[0],'go')
    axes[1].plot(len(profile)-1,profile[-1],'ro')
    axes[1].set_title('Profile across edges array')
    axes[1].set_xlabel('Pixel distance')


# Run functions in order ======================================================

# Example edge binary image
test_file = pth.join('.', 'tests', 'test_data', '10_circles_colour.gif')
image_in = load_image(test_file)
z = detect_edge(image_in)

# Select coords
coords = binaryarray2coords(z)

# Calculate profile from coords
profile = coords2profile(coords)

# Plot result
plot_edges_profile(z,coords,profile)