Pix2Text icon indicating copy to clipboard operation
Pix2Text copied to clipboard

Index out of bounds when merging text

Open tonyzdev opened this issue 2 years ago • 1 comments

    for _out in outs:
        line_number = _out.get('line_number', 0) + 1
        if len(out_texts) <= line_number:
            out_texts.append([])
            line_margin_list.append([0, 0])
            isolated_included.append(False)
        cur_text = _out['text']
        if _out['type'] in ('embedding', 'isolated'):
            sep = isolated_sep if _out['type'] == 'isolated' else embed_sep
            cur_text = sep[0] + cur_text + sep[1]
        if _out['type'] == 'isolated':
            isolated_included[line_number] = True
            cur_text = line_sep + cur_text + line_sep
        out_texts[line_number].append(cur_text)
        line_margin_list[line_number][1] = max(
            line_margin_list[line_number][1], float(_out['position'][2, 0])
        )
        line_margin_list[line_number][0] = min(
            line_margin_list[line_number][0], float(_out['position'][0, 0])
        )
    line_text_list = [smart_join(o) for o in out_texts]

when the case occurs that out_texts[-1] is a blank list, length of out_texts will be smaller 1 than length of line_number, it should cause index out of bounds.

tonyzdev avatar Apr 02 '24 16:04 tonyzdev

try to upgrade to the new version: v1.0.2.3

breezedeus avatar Apr 03 '24 11:04 breezedeus