Esempio n. 1
0
def get_stroke_sequence(filename, resample=False, first_stroke_0=False):
    tree = ElementTree.parse(filename).getroot()
    strokes = [i for i in tree if i.tag == 'StrokeSet'][0]

    coords = []
    for stroke in strokes:
        for i, point in enumerate(stroke):
            coords.append([
                int(point.attrib['x']), -1 * int(point.attrib['y']),
                int(i == len(stroke) - 1)
            ])
    coords = np.array(coords)

    # coords2 = drawing.align(coords.copy())
    # coords2 = drawing.denoise(coords)
    # offsets2 = drawing.coords_to_offsets(coords2)
    # #offsets = offsets[:drawing.MAX_STROKE_LEN] These are excluded later, truncating them would prevent exclusion
    # offsets2 = drawing.normalize(offsets2)

    if resample:
        coords = utils.resample_coords(coords)

    coords = drawing.align(coords)
    coords = drawing.denoise(coords)
    offsets = drawing.coords_to_offsets(coords, first_stroke_0=first_stroke_0)
    #offsets = offsets[:drawing.MAX_STROKE_LEN] These are excluded later, truncating them would prevent exclusion
    offsets = drawing.normalize(offsets)

    return coords, offsets
Esempio n. 2
0
def get_stroke_sequence(sampleStrokes):

    strokes = sampleStrokes

    coords = []
    if strokes[0][2] < 0.5:
        coords = [[0, 0, 1]]

    for i, point in enumerate(strokes):
        coords.append([int(point[0]), -1 * int(point[1]), point[2]])
    coords = np.array(coords)

    coords = drawing.align(coords)
    coords = drawing.denoise(coords)
    offsets = drawing.coords_to_offsets(coords)
    offsets = offsets[:drawing.MAX_STROKE_LEN]
    offsets = drawing.normalize(offsets)
    return offsets
def get_stroke_sequence(filename):
    tree = ElementTree.parse(filename).getroot()
    strokes = [i for i in tree if i.tag == 'StrokeSet'][0]

    coords = []
    for stroke in strokes:
        for i, point in enumerate(stroke):
            coords.append([
                int(point.attrib['x']), -1 * int(point.attrib['y']),
                int(i == len(stroke) - 1)
            ])
    coords = np.array(coords)

    coords = drawing.align(coords)
    coords = drawing.denoise(coords)
    offsets = drawing.coords_to_offsets(coords)
    offsets = offsets[:drawing.MAX_STROKE_LEN]
    offsets = drawing.normalize(offsets)
    return offsets
def preprocess(sampleStrokes):

    strokes = sampleStrokes

    coords = []
    if strokes[0].penUp < 0.5:
        coords = [[0, 0, 1]]

    for i, point in enumerate(strokes):
        coords.append([int(point.pos[0]), -1 * int(point.pos[1]), point.penUp])
    coords = np.array(coords)

    coords = drawing.align(coords)
    coords = drawing.denoise(coords)
    offsets = drawing.coords_to_offsets(coords)
    offsets = offsets[:drawing.MAX_STROKE_LEN]
    offsets, normalizationFactor = drawing.normalize(
        offsets, returnNormalizationFactor=True)
    return offsets, normalizationFactor
def get_stroke_sequence(filename):
    tree = ElementTree.parse(filename).getroot()
    strokes = [i for i in tree if i.tag == 'StrokeSet'][0]

    coords = []
    for stroke in strokes:
        for i, point in enumerate(stroke):
            coords.append([
                int(point.attrib['x']),
                -1*int(point.attrib['y']),
                int(i == len(stroke) - 1)
            ])
    coords = np.array(coords)

    coords = drawing.align(coords)
    coords = drawing.denoise(coords)
    offsets = drawing.coords_to_offsets(coords)
    offsets = offsets[:drawing.MAX_STROKE_LEN]
    offsets = drawing.normalize(offsets)
    return offsets
Esempio n. 6
0
def convert_gts_to_synth_format(stroke, adjustments=True):
    new_stroke = stroke[:, :3].copy()
    if np.any(new_stroke[:, -1] >= 2):
        #raise Exception("Input data is in stroke number format")
        warnings.warn("Input data is in stroke number format")
        new_stroke[:, -1] = stroke_recovery.relativefy(new_stroke[:, -1])
        assert not np.any(new_stroke[:, -1] >= 2)
    # Round SOS
    new_stroke[:, -1] = np.round(new_stroke[:, -1])

    #if np.all(new_stroke[0,:2] != 0):
    #new_stroke = np.concatenate([np.array([[0,0,0]]), new_stroke], axis=0)

    # Convert to EOS
    coords = sos_to_eos(new_stroke)
    if adjustments:
        coords = drawing.align(coords)
        coords = drawing.denoise(coords)
    offsets = drawing.coords_to_offsets(coords)
    offsets = offsets[:drawing.MAX_STROKE_LEN]
    offsets = drawing.normalize(offsets)
    return offsets