def check_file(file_path):
    with open(file_path) as f:
        data = json.loads(f.read())
    rects = [s["points"] for s in data["shapes"]]
    labels = [s["label"] for s in data["shapes"]]
    n = 0
    for i, lbl in enumerate(labels):
        try:
            lt.human_label_to_int(lbl)
        except Exception as e:
            print(file_path)
            print(e)
            print(lbl, rects[i])
Esempio n. 2
0
def string_to_line(text_line):
    '''
    :param text_line: single line text
    :return: Line (not postprocessed)
    '''
    ext_mode = False
    line = None
    spaces_before = 0
    for ch in text_line:
        if ch == '~':
            if not ext_mode:
                ext_mode = True
                ext_ch = ''
                ch = None
            else:
                ext_mode = False
                if ext_ch.isdigit():
                    ext_ch = '~'+ext_ch
                ch = ext_ch
        if ch:
            if ext_mode:
                ext_ch += ch
            else:
                if ch == ' ':
                    spaces_before += 1
                else:
                    label = lt.human_label_to_int(ch)
                    if line is None:
                        line = Line(box=[0,0,0,0], label=label)
                    else:
                        line.chars.append(LineChar(box=[0,0,0,0], label=label))
                    line.chars[-1].spaces_before = spaces_before
                    spaces_before = 0
    assert not ext_mode, text_line
    return line
Esempio n. 3
0
def read_LabelMe_annotation(label_filename, get_points):
    '''
    Reads LabelMe (see https://github.com/IlyaOvodov/labelme labelling tool) annotation JSON file.
    :param label_filename: path to LabelMe annotation JSON file
    :return: list of rect objects. Each rect object is a tuple (left, top, right, bottom, label) where
        left..bottom are in [0,1), label is int in [1..63]
    '''
    if get_points:
        raise NotImplementedError(
            "read_annotation get_point mode not implemented for LabelMe annotation"
        )
    with open(label_filename, 'r', encoding='cp1251') as opened_json:
        loaded = json.load(opened_json)
    convert_x = limiting_scaler(loaded["imageWidth"], 1.0)
    convert_y = limiting_scaler(loaded["imageHeight"], 1.0)
    rects = [(
        convert_x(min(xvals)),
        convert_y(min(yvals)),
        convert_x(max(xvals)),
        convert_y(max(yvals)),
        lt.human_label_to_int(label),
    ) for label, xvals, yvals in ((shape["label"],
                                   [coords[0] for coords in shape["points"]],
                                   [coords[1] for coords in shape["points"]])
                                  for shape in loaded["shapes"])]
    return rects