def run(img): extracted = extract_paper(img) graph = sketch_graph(extracted) graph = hv_lines(graph, extracted) svg = printer.graph_to_svg(graph) 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)
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)
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
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
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)