Example #1
0
def run(img):
    img = vision.convert_hsv_image_to_greyscale_emphasising_saturation(img)
    ink = vision.binarize_ink_IMPROVED(img)
    log.bgrOrGreyImage(ink)

    skeleton = vision.skeletonize(ink)
    log.bgrOrGreyImage(skeleton)

    graph = topology.produce_graph(skeleton)
    log.hsvOrGreyImage(img, pixels=graph.nodes())
    log.gpickle(graph)

    return graph
Example #2
0
def run(graph, img):
    graph = topology.simplify_junctures(graph)
    log.hsvOrGreyImage(img,
        points=(node for node in graph.nodes() if graph.degree(node) != 2)
    )

    graph = topology.simplify_paths(graph)
    log.hsvOrGreyImage(img,
        points=graph.nodes(),
        lines=graph.edges()
    )

    graph = topology.hv_lines(graph)
    log.hsvOrGreyImage(img,
        points=graph.nodes(),
        lines=graph.edges()
    )

    graph = satisfaction.align(graph)
    log.hsvOrGreyImage(img,
        points=graph.nodes(),
        lines=graph.edges()
    )

    return graph
Example #3
0
def run(img):
    img = vision.convert_hsv_image_to_greyscale_emphasising_saturation(img)
    ink = vision.binarize_ink_IMPROVED(img)
    log.bgrOrGreyImage(ink)

    skeleton = vision.skeletonize(ink)
    log.bgrOrGreyImage(skeleton)

    graph = topology.produce_graph(skeleton)
    log.hsvOrGreyImage(img,
        pixels=graph.nodes()
    )
    log.gpickle(graph)

    return graph
Example #4
0
def run(img):
    img = extract_paper(img)

    graph = sketch_graph(img)

    graph = topology.simplify_junctures(graph)
    log.hsvOrGreyImage(img, pixels=graph.nodes(), points=(node for node in graph.nodes() if graph.degree(node) != 2))

    paths = topology.find_paths(graph)

    corners = []
    for path in paths:
        corners.extend(corner_detection.find_corners(path))

    log.hsvOrGreyImage(img, points=corners)

    return graph
Example #5
0
def run(img):
    img = extract_paper(img)

    graph = sketch_graph(img)

    graph = topology.simplify_junctures(graph)
    log.hsvOrGreyImage(img,
                       pixels=graph.nodes(),
                       points=(node for node in graph.nodes()
                               if graph.degree(node) != 2))

    paths = topology.find_paths(graph)

    corners = []
    for path in paths:
        corners.extend(corner_detection.find_corners(path))

    log.hsvOrGreyImage(img, points=corners)

    return graph
Example #6
0
def run(img):
    img = extract_paper(img)

    graph = sketch_graph(img)

    components = nx.connected_components(graph)

    circles = [
        topology.fit_circle_to_points(list(component))
        for component in components
    ]

    log.hsvOrGreyImage(img, circles=circles)

    svg = printer.circles_to_svg(circles)
    printer.write_file("log/out.svg", svg)
    pdf = printer.svg_to_pdf("log/out.svg", "log/out.pdf")
    printer.write_file("log/out.pdf", pdf)
    # printer.print_pdf("log/out.pdf")

    return graph
Example #7
0
def run(img, logOn=True):
    white_balanced_image = vision.white_balance(img)
    hsv = cv2.cvtColor(white_balanced_image, cv2.COLOR_BGR2HSV)
    if logOn: log.hsvOrGreyImage(hsv)
    
    edges = vision.find_edges(hsv)
    if logOn: log.hsvOrGreyImage(edges)
    
    paper_contour = vision.find_paper(edges)
    if logOn: log.hsvOrGreyImage(hsv, contours=[paper_contour])
    
    extracted = vision.extract_paper(hsv, paper_contour)
    if logOn: log.hsvOrGreyImage(extracted)
    
    return extracted
Example #8
0
def run(img, logOn=True):
    white_balanced_image = vision.white_balance(img)
    hsv = cv2.cvtColor(white_balanced_image, cv2.COLOR_BGR2HSV)
    if logOn: log.hsvOrGreyImage(hsv)

    edges = vision.find_edges(hsv)
    if logOn: log.hsvOrGreyImage(edges)

    paper_contour = vision.find_paper(edges)
    if logOn: log.hsvOrGreyImage(hsv, contours=[paper_contour])

    extracted = vision.extract_paper(hsv, paper_contour)
    if logOn: log.hsvOrGreyImage(extracted)

    return extracted
Example #9
0
def run(img):
    log.bgrOrGreyImage(img)
    hsv = extract_paper(img, logOn=False)
    log.hsvOrGreyImage(hsv)
    grey = vision.convert_hsv_image_to_greyscale_emphasising_saturation(hsv)
    binarized = vision.binarize_ink_IMPROVED(grey)
    log.hsvOrGreyImage(binarized)

    skeleton = vision.skeletonize(binarized)
    log.hsvOrGreyImage(skeleton)

    black = np.zeros((hsv.shape[0], hsv.shape[1], 3), dtype=np.uint8)

    graph = topology.produce_graph(skeleton, hsv_image=hsv)
    log.hsvOrGreyImage(black, pixels=graph.nodes(), graph=graph)

    graph = topology.simplify_junctures(graph)
    log.hsvOrGreyImage(
        black,
        pixels=graph.nodes(),
        # lines=graph.edges(),
        graph=graph,
    )

    mygraph, constraint_junctions = topology.find_same_length_constraints(graph)
    log.hsvOrGreyImage(black, points=constraint_junctions, lines=mygraph.edges(), graph=mygraph)

    graph = topology.simplify_paths(graph)
    log.hsvOrGreyImage(black, points=graph.nodes(), lines=graph.edges())

    graph = topology.hv_lines(graph)
    log.hsvOrGreyImage(hsv, points=graph.nodes(), lines=graph.edges())

    graph = satisfaction.align(graph)
    log.hsvOrGreyImage(hsv, points=graph.nodes(), lines=graph.edges())

    satisfaction.apply_same_length_constraint(graph)
Example #10
0
def run(img):
    log.bgrOrGreyImage(img)
    hsv = extract_paper(img, logOn=False)
    log.hsvOrGreyImage(hsv)
    grey = vision.convert_hsv_image_to_greyscale_emphasising_saturation(hsv)
    binarized = vision.binarize_ink_IMPROVED(grey)
    log.hsvOrGreyImage(binarized)
    
    skeleton = vision.skeletonize(binarized)
    log.hsvOrGreyImage(skeleton)
    
    black = np.zeros((hsv.shape[0], hsv.shape[1], 3), dtype=np.uint8)
    
    graph = topology.produce_graph(skeleton, hsv_image=hsv)
    log.hsvOrGreyImage(black,
        pixels=graph.nodes(),
        graph=graph
    )
    
    graph = topology.simplify_junctures(graph)
    log.hsvOrGreyImage(black,
        pixels=graph.nodes(),
        # lines=graph.edges(),
        graph=graph
    )
    
    mygraph, constraint_junctions = topology.find_same_length_constraints(graph)
    log.hsvOrGreyImage(black,
        points=constraint_junctions,
        lines=mygraph.edges(),
        graph=mygraph
    )
    
    graph = topology.simplify_paths(graph)
    log.hsvOrGreyImage(black,
        points=graph.nodes(),
        lines=graph.edges()
    )
    
    graph = topology.hv_lines(graph)
    log.hsvOrGreyImage(hsv,
        points=graph.nodes(),
        lines=graph.edges()
    )
    
    graph = satisfaction.align(graph)
    log.hsvOrGreyImage(hsv,
        points=graph.nodes(),
        lines=graph.edges()
    )
    
    satisfaction.apply_same_length_constraint(graph)