Exemplo n.º 1
0
def get_lines_within_bbox(bbox, segments):
    lines_within_bbox = []
    for line in segments:
        bbox_line = (int(line.y0), int(line.x0), int(line.y1), int(line.x1))
        if isContained(bbox_line, bbox[-4:]):
            lines_within_bbox += [line]
    return lines_within_bbox
Exemplo n.º 2
0
def get_mentions_within_bbox(bbox, mentions):
    mentions_within_bbox = []
    for mention in mentions:
        bbox_mention = (
            int(mention.y0),
            int(mention.x0),
            int(mention.y1),
            int(mention.x1),
        )
        if isContained(bbox_mention, bbox[-4:]):
            mentions_within_bbox += [mention]
    return mentions_within_bbox
Exemplo n.º 3
0
def get_mentions_within_bbox(bbox: List[Any],
                             mentions: List[LTComponent]) -> List[LTComponent]:
    """Get textlines within bbox.

    :param bbox: a list containing (top, left, bottom, right) in the last 4 digits
    :param mentions: a list of textlines
    :return: a list of textlines within the given bbox
    """
    mentions_within_bbox = []
    for mention in mentions:
        # Compute the centroid
        xc = int((mention.x0 + mention.x1) / 2)
        yc = int((mention.y0 + mention.y1) / 2)
        bbox_mention = (
            yc,
            xc,
            yc,
            xc,
        )
        # See if the centroid is contained by the bbox.
        if isContained(bbox_mention, bbox[-4:]):
            mentions_within_bbox += [mention]
    return mentions_within_bbox