Esempio n. 1
0
async def make_annotations(ann, test):
    if ann['category_id'] == 4:
        header = Cell(ann['bbox'][0], ann['bbox'][1], ann['bbox'][0] +
                      ann['bbox'][2], ann['bbox'][1] + ann['bbox'][3])
        return header, 0
    elif ann['category_id'] == 2:
        text = await get_text_from_one_cell(test, ann)
        if text[0]:
            text = text[0].replace('\n', ' ')
            # print("Cell: ", text)
            cell = Cell(ann['bbox'][0], ann['bbox'][1], ann['bbox'][0] + ann['bbox'][2],
                        ann['bbox'][1] + ann['bbox'][3], text_boxes=text)
            # print(cell.text_boxes)
            return cell, 1
    return 2, 2
Esempio n. 2
0
def _raw_to_cell(raw_cell: Dict[str, Any]) -> Cell:
    return Cell(
        top_left_x=raw_cell["bbox"][0],
        top_left_y=raw_cell["bbox"][1],
        bottom_right_x=raw_cell["bbox"][2],
        bottom_right_y=raw_cell["bbox"][3],
        confidence=raw_cell["score"],
    )
Esempio n. 3
0
def text_to_cell(text_field: TextField):
    return Cell(
        top_left_x=text_field.bbox.top_left_x,
        top_left_y=text_field.bbox.top_left_y,
        bottom_right_x=text_field.bbox.bottom_right_x,
        bottom_right_y=text_field.bbox.bottom_right_y,
        text_boxes=[text_field],
    )
Esempio n. 4
0
def boxes_to_image_obj(path: Path, boxes, origin):
    y0, x0 = origin
    # Convert (x,y,w,h -> x1,x2,y1,y2 and shift according to origin)
    new_boxes = []
    for box in boxes:
        x, y, w, h = box
        new_boxes.append(Cell(x + x0, y + y0, x + x0 + w, y + y0 + h))
    img_data = Image(path, None, None, objs=new_boxes, bboxes=[])
    # boxes = [(b[0] + x0, b[1] + y0, b[2], b[3]) for b in boxes]
    return img_data
Esempio n. 5
0
def box_to_cell(box, table_origin_shift) -> Cell:
    y0, x0 = table_origin_shift
    x, y, w, h = box
    return Cell(x + x0, y + y0, x + x0 + w, y + y0 + h)