예제 #1
0
def save_parse_image_segments():
    question = geoserver_interface.download_questions(1037).values()[0]
    image_segment_parse = parse_image_segments(
        open_image(question.diagram_path))
    image = image_segment_parse.diagram_image_segment.segmented_image
    file_path = "/Users/minjoon/Desktop/diagram.png"
    cv2.imwrite(file_path, image)
예제 #2
0
def diagram_to_graph_parse(diagram):
    image_segment_parse = parse_image_segments(diagram)
    primitive_parse = parse_primitives(image_segment_parse)
    selected_primitive_parse = select_primitives(primitive_parse)
    core_parse = parse_core(selected_primitive_parse)
    graph_parse = parse_graph(core_parse)
    return graph_parse
예제 #3
0
def test_parse_graph():
    questions = geoserver_interface.download_questions(973).values()
    for question in questions:
        image_segment_parse = parse_image_segments(
            open_image(question.diagram_path))
        primitive_parse = parse_primitives(image_segment_parse)
        selected_primitive_parse = select_primitives(primitive_parse)
        core_parse = parse_core(selected_primitive_parse)
        graph_parse = parse_graph(core_parse)

        print("Confident information in the diagram:")
        for variable_node in parse_confident_atoms(graph_parse):
            print variable_node

        core_parse.display_points()
        lines = get_all_instances(graph_parse, 'line')
        circles = get_all_instances(graph_parse, 'circle')
        arcs = get_all_instances(graph_parse, 'arc')
        angles = get_all_instances(graph_parse, 'angle')
        print("Displaying lines...")
        for key, line in lines.iteritems():
            graph_parse.display_instances([line])
        print("Displaying circles...")
        for key, circle in circles.iteritems():
            graph_parse.display_instances([circle])
        print("Displaying arcs...")
        for key, arc in arcs.iteritems():
            graph_parse.display_instances([arc])
        print("Displaying angles...")
        for key, angle in angles.iteritems():
            graph_parse.display_instances([angle])
예제 #4
0
def save_parse_primitives():
    question = geoserver_interface.download_questions(1037).values()[0]
    image_segment_parse = parse_image_segments(open_image(question.diagram_path))
    primitive_parse = parse_primitives(image_segment_parse)
    image = primitive_parse.get_image_primitives()
    file_path = "/Users/minjoon/Desktop/primitives.png"
    cv2.imwrite(file_path, image)
예제 #5
0
def test_parse_graph():
    questions = geoserver_interface.download_questions(973).values()
    for question in questions:
        image_segment_parse = parse_image_segments(open_image(question.diagram_path))
        primitive_parse = parse_primitives(image_segment_parse)
        selected_primitive_parse = select_primitives(primitive_parse)
        core_parse = parse_core(selected_primitive_parse)
        graph_parse = parse_graph(core_parse)

        print("Confident information in the diagram:")
        for variable_node in parse_confident_atoms(graph_parse):
            print variable_node

        core_parse.display_points()
        lines = get_all_instances(graph_parse, 'line')
        circles = get_all_instances(graph_parse, 'circle')
        arcs = get_all_instances(graph_parse, 'arc')
        angles = get_all_instances(graph_parse, 'angle')
        print("Displaying lines...")
        for key, line in lines.iteritems():
            graph_parse.display_instances([line])
        print("Displaying circles...")
        for key, circle in circles.iteritems():
            graph_parse.display_instances([circle])
        print("Displaying arcs...")
        for key, arc in arcs.iteritems():
            graph_parse.display_instances([arc])
        print("Displaying angles...")
        for key, angle in angles.iteritems():
            graph_parse.display_instances([angle])
예제 #6
0
def question_to_graph_parse(question):
    diagram = open_image(question.diagram_path)
    image_segment_parse = parse_image_segments(diagram)
    primitive_parse = parse_primitives(image_segment_parse)
    selected_primitive_parse = select_primitives(primitive_parse)
    core_parse = parse_core(selected_primitive_parse)
    graph_parse = parse_graph(core_parse)
    return graph_parse
예제 #7
0
def save_parse_primitives():
    question = geoserver_interface.download_questions(1037).values()[0]
    image_segment_parse = parse_image_segments(
        open_image(question.diagram_path))
    primitive_parse = parse_primitives(image_segment_parse)
    image = primitive_parse.get_image_primitives()
    file_path = "/Users/minjoon/Desktop/primitives.png"
    cv2.imwrite(file_path, image)
예제 #8
0
def question_to_graph_parse(question):
    diagram = open_image(question.diagram_path)
    image_segment_parse = parse_image_segments(diagram)
    primitive_parse = parse_primitives(image_segment_parse)
    selected_primitive_parse = select_primitives(primitive_parse)
    core_parse = parse_core(selected_primitive_parse)
    graph_parse = parse_graph(core_parse)
    return graph_parse
예제 #9
0
def test_select_primitives():
    question_dict = geoserver_interface.download_questions('test')
    for key in sorted(question_dict.keys()):
        question = question_dict[key]
        print(key)
        image_segment_parse = parse_image_segments(open_image(question.diagram_path))
        primitive_parse = parse_primitives(image_segment_parse)
        selected = select_primitives(primitive_parse)
        selected.display_primitives()
예제 #10
0
def test_parse_image_segments():
    question = geoserver_interface.download_questions(1037).values()[0]
    image_segment_parse = parse_image_segments(
        open_image(question.diagram_path))
    image_segment_parse.diagram_image_segment.display_binarized_segmented_image(
    )
    for idx, label_image_segment in image_segment_parse.label_image_segments.iteritems(
    ):
        label_image_segment.display_segmented_image()
예제 #11
0
def test_select_primitives():
    question_dict = geoserver_interface.download_questions('test')
    for key in sorted(question_dict.keys()):
        question = question_dict[key]
        print(key)
        image_segment_parse = parse_image_segments(
            open_image(question.diagram_path))
        primitive_parse = parse_primitives(image_segment_parse)
        selected = select_primitives(primitive_parse)
        selected.display_primitives()
예제 #12
0
def save_select_primitives():
    question_dict = geoserver_interface.download_questions('test')
    folder_path = "/Users/minjoon/Desktop/selected/"
    for key in sorted(question_dict.keys()):
        question = question_dict[key]
        print(key)
        image_segment_parse = parse_image_segments(open_image(question.diagram_path))
        primitive_parse = parse_primitives(image_segment_parse)
        selected = select_primitives(primitive_parse)
        image = selected.get_image_primitives()
        cv2.imwrite(os.path.join(folder_path, "%s.png" % str(question.key)), image)
예제 #13
0
def save_select_primitives():
    question_dict = geoserver_interface.download_questions('test')
    folder_path = "/Users/minjoon/Desktop/selected/"
    for key in sorted(question_dict.keys()):
        question = question_dict[key]
        print(key)
        image_segment_parse = parse_image_segments(
            open_image(question.diagram_path))
        primitive_parse = parse_primitives(image_segment_parse)
        selected = select_primitives(primitive_parse)
        image = selected.get_image_primitives()
        cv2.imwrite(os.path.join(folder_path, "%s.png" % str(question.key)),
                    image)
예제 #14
0
def save_parse_core():
    question_dict = geoserver_interface.download_questions('test')
    folder_path = "/Users/minjoon/Desktop/core/"
    for key in sorted(question_dict.keys()):
        print(key)
        question = question_dict[key]
        file_path = os.path.join(folder_path, str(question.key) + ".png")
        if os.path.isfile(file_path):
            continue
        image_segment_parse = parse_image_segments(open_image(question.diagram_path))
        primitive_parse = parse_primitives(image_segment_parse)
        selected = select_primitives(primitive_parse)
        core_parse = parse_core(selected)
        image = core_parse.get_image_points()
        cv2.imwrite(file_path, image)
예제 #15
0
def save_parse_core():
    question_dict = geoserver_interface.download_questions('test')
    folder_path = "/Users/minjoon/Desktop/core/"
    for key in sorted(question_dict.keys()):
        print(key)
        question = question_dict[key]
        file_path = os.path.join(folder_path, str(question.key) + ".png")
        if os.path.isfile(file_path):
            continue
        image_segment_parse = parse_image_segments(
            open_image(question.diagram_path))
        primitive_parse = parse_primitives(image_segment_parse)
        selected = select_primitives(primitive_parse)
        core_parse = parse_core(selected)
        image = core_parse.get_image_points()
        cv2.imwrite(file_path, image)
예제 #16
0
def test_parse_primitives():
    question = geoserver_interface.download_questions(1037).values()[0]
    image_segment_parse = parse_image_segments(
        open_image(question.diagram_path))
    primitive_parse = parse_primitives(image_segment_parse)
    primitive_parse.display_primitives()
예제 #17
0
def test_parse_primitives():
    question = geoserver_interface.download_questions(1037).values()[0]
    image_segment_parse = parse_image_segments(open_image(question.diagram_path))
    primitive_parse = parse_primitives(image_segment_parse)
    primitive_parse.display_primitives()
예제 #18
0
def save_parse_image_segments():
    question = geoserver_interface.download_questions(1037).values()[0]
    image_segment_parse = parse_image_segments(open_image(question.diagram_path))
    image = image_segment_parse.diagram_image_segment.segmented_image
    file_path = "/Users/minjoon/Desktop/diagram.png"
    cv2.imwrite(file_path, image)
예제 #19
0
def test_parse_image_segments():
    question = geoserver_interface.download_questions(1037).values()[0]
    image_segment_parse = parse_image_segments(open_image(question.diagram_path))
    image_segment_parse.diagram_image_segment.display_binarized_segmented_image()
    for idx, label_image_segment in image_segment_parse.label_image_segments.iteritems():
        label_image_segment.display_segmented_image()
예제 #20
0
from geosolver.diagram.parse_image_segments import parse_image_segments
from geosolver.diagram.parse_primitives import parse_primitives
from geosolver.diagram.select_primitives import select_primitives
from geosolver.diagram.parse_core import parse_core
from geosolver.diagram.parse_graph import parse_graph
from geosolver.diagram.get_instances import get_all_instances

from geosolver.utils import prep
from geosolver.diagram.draw_on_image import *
import cv2
# demonstrate the image & parse image segments
image_path = 'tmp/all_images/8765.png'

image_segment_parse = parse_image_segments(prep.open_image(image_path))
# image_segment_parse.diagram_image_segment.display_segmented_image()
# prep.save_image(image_segment_parse.diagram_image_segment.segmented_image, 'tmp/t.png')
cv2.imwrite('tmp/results/source1.png', image_segment_parse.diagram_image_segment.segmented_image)
cv2.imwrite('tmp/results/sourceb.png', 255-image_segment_parse.diagram_image_segment.binarized_segmented_image)

# parse the primitive
primitive_parse = parse_primitives(image_segment_parse)
# primitive_parse.display_primitives()
cv2.imwrite('tmp/results/primitive1.png', primitive_parse.get_image_primitives())

# select the best set of primitive
selected = select_primitives(primitive_parse)
# selected.display_primitives()
cv2.imwrite('tmp/results/selected1.png', selected.get_image_primitives())

# point clustering
core_parse = parse_core(selected)