예제 #1
0
def test_input_4():
    image = reader.read_and_process('tests/fixtures/4.jpg')
    stations = identifier.identify_countors(image)
    triangles = helper.filter_triangles(stations)
    squares = helper.filter_squares(stations)
    circles = helper.filter_circles(stations)

    assert len(triangles) == 5
    assert len(squares) == 2
    assert len(circles) == 10
    # total
    assert len(stations) == 17
예제 #2
0
def test_input_5():
    image = reader.read_and_process('tests/fixtures/5.jpg')
    stations = identifier.identify_countors(image)
    triangles = helper.filter_triangles(stations)
    squares = helper.filter_squares(stations)
    droplets = helper.filter_droplets(stations)
    circles = helper.filter_circles(stations)
    crosses = helper.filter_crosses(stations)

    assert len(triangles) == 4
    assert len(squares) == 2
    assert len(droplets) == 1
    assert len(circles) == 10
    assert len(crosses) == 1
    # total
    assert len(stations) == 18
예제 #3
0
def test_input_1():
    image = reader.read_and_process('tests/fixtures/1.jpg')
    stations = identifier.identify_countors(image)
    triangles = helper.filter_triangles(stations)
    circles = helper.filter_circles(stations)
    squares = helper.filter_squares(stations)
    rhombus = helper.filter_rhombuses(stations)
    pentagons = helper.filter_pentagons(stations)
    droplets = helper.filter_droplets(stations)
    stars = helper.filter_stars(stations)
    crosses = helper.filter_crosses(stations)

    assert len(triangles) == 9
    assert len(squares) == 1
    assert len(rhombus) == 1
    assert len(pentagons) == 1
    assert len(droplets) == 1
    assert len(circles) == 18
    assert len(stars) == 1
    assert len(crosses) == 1
    # total
    assert len(stations) == 33
예제 #4
0
from services import reader, identifier, solver, drawer, utils
from cv2 import cv2
import sys
import os

file_path = sys.argv[1]
image = reader.read(file_path)
proc_image = reader.process_image(image)

# detect stations
stations = identifier.identify_countors(proc_image)
utils.print_table(stations, title='Stations', hide_columns=['contour'])

# detect rivers
rivers = identifier.identify_rivers(image)

# optimize routes
routes = solver.solve(stations, rivers)
utils.print_table(routes, title='Routes')

# draw
results = drawer.draw_results(proc_image, stations, rivers, routes)

file_name = os.path.basename(file_path)
cv2.imwrite('outputs/%s' % file_name, results)
print()
print('Results saved in outputs/%s' % file_name)