Exemplo n.º 1
0
 def __init__(self, filename, labeled=False):
     self.labeled = labeled
     self.groups = self.labels = self.templates = []
     self.filename = filename
     self.filename_base = os.path.splitext(os.path.basename(filename))[0]
     
     if labeled:
         (self.templates, self.groups, self.labels) = load_page(filename)
     else:
         self.templates = single_stroke_unlabeled_file(filename)
         self.labels = ['NO LABEL' for i in range(len(self.templates))]
         
     self.pen = os.path.split(os.path.dirname(filename))[1]
     self.num_temps = len(self.templates)
Exemplo n.º 2
0
 def load_raw_strokes_old(self):
     #self.labelFileName = '/home/david/Dropbox/Research/Data/PencaseDataFix/Pen006/Homework6-Problem1-text.iv'
     self.labelFileName = str(QFileDialog.getOpenFileName())
     if isfile(self.labelFileName):
         self.pen = basename(dirname(self.labelFileName))
         self.file_name = splitext(basename(self.labelFileName))[0]
         self.templates = imageio.single_stroke_unlabeled_file(self.labelFileName)
         self.num_temps = len(self.templates)
         self.stroke_handles = []
         self.labels = []
         self.groupings = []
         self.ui.matplot.canvas.ax.clear()
         for i, t in enumerate(self.templates):
             x,y = zip(*t.points)
             h, = self.ui.matplot.canvas.ax.plot(x,y, 'k', picker=5)
             h.index = i;
             self.stroke_handles.append(h)
             self.current_page.labels.append('NO LABEL')
         self.ui.matplot.canvas.draw()
         self.max_xlim = self.ui.matplot.canvas.ax.get_xlim()
         self.max_ylim = self.ui.matplot.canvas.ax.get_ylim()
         self.zoom_fun = zoom_factory(self.ui.matplot.canvas, self.max_xlim,
                                      self.max_ylim, 1.5)
Exemplo n.º 3
0
from sketchrec import grouping, imageio
import numpy as np

temp_file = 'tests/test_page.iv'
#grp_file = 'tests/test_page.grp'
#lbl_file = 'tests/test_page.lbl'

temps = imageio.single_stroke_unlabeled_file(temp_file)
#groups = imageio.load_group_file(grp_file)
#labels = imageio.load_label_file(lbl_file)

def basic_tests():
    lines = grouping.equation_lines(temps)
    assert (np.max([v for line in lines for v in line]) + 1) == len(temps)

def group_convert_test():
    groups = [[1], [2,3,4], [5], [6,8,9], [7]]
    join_graph = grouping.groups_to_join_graph(groups)
    assert  join_graph == {1:[1], 2:[2, 3, 4], 3:[2, 3, 4],
                           4:[2, 3, 4], 5:[5], 6:[6, 8, 9],
                           7:[7], 8:[6, 8, 9], 9:[6, 8, 9]}
    new_groups = grouping.join_graph_to_groups(join_graph)
    assert len(new_groups) == len(groups)
    for g1, g2 in zip(new_groups, groups):
        assert g1 == g2

    sparse_groups = [[2,3], [5, 7, 10], [8,11], [12, 13]]
    all_groups = grouping.sparse_groups_to_groups(sparse_groups, 14)
    real_all_groups = [[0], [1], [2, 3], [4], [5, 7, 10], [6], [8,11],
                       [9], [12, 13]]
    for g1, g2 in zip(all_groups, real_all_groups):