pycognaize.document.tag.tag.BoxTag

class BoxTag(left, right, top, bottom, page, confidence=None)[source]

Bases: Tag

Represents a tag that has a varying width and height

Parameters:
  • left (Union[int, float])

  • right (Union[int, float])

  • top (Union[int, float])

  • bottom (Union[int, float])

  • page (Page)

  • confidence (Confidence)

Methods

construct_from_raw

distance

Return the Euclidean distance of two tag centers

get_top_left

get_width_height

hshift

Shifts rectangle horizontally

intersects

Checks id there is an intersection between this and other rectangle

iou

Calculate Intersection over Union for given rectangles

is_in_rectangle

Check if the rectangle is in the other rectangle

set_class_confidence

shift

Shifts rectangle by 2 axes simultaneously

to_dict

Return a dictionary representing the tag object

vshift

Shifts rectangle vertically

Attributes

area

Area of the rectangle

bottom

center

Center point of the rectangle

confidence

height

Height of the rectangle

left

page

right

top

width

Width of the rectangle

xcenter

Center of horizontal line of the rectangle

ycenter

Center of vertical line of the rectangle

__add__(other)[source]

Merge two rectangles into one

Parameters:

other (Union[BoxTag, Cell])

Return type:

BoxTag

property area: float

Area of the rectangle

property center: Tuple[float, float]

Center point of the rectangle

distance(other)[source]

Return the Euclidean distance of two tag centers

Parameters:

other (BoxTag)

Return type:

Union[int, float]

property height: int | float

Height of the rectangle

hshift(by)[source]

Shifts rectangle horizontally

Parameters:

by – the amount by which the tag should be horizontally shifted

Return type:

BoxTag

Returns:

shifted rectangle

intersects(other)[source]

Checks id there is an intersection between this and other rectangle

Parameters:

other (Union[BoxTag, Cell]) – Rectangle object

Return type:

bool

iou(other)[source]

Calculate Intersection over Union for given rectangles

Return type:

Union[int, float]

is_in_rectangle(other, thresh)[source]

Check if the rectangle is in the other rectangle

Parameters:
  • other (BoxTag) – Another rectangle object

  • thresh (float) – If the fraction area of the rectangle is in the other rectangle is larger or equal to thresh, it is in the other rectangle

Return type:

bool

Returns:

True if rectangle is in other rectangle, False otherwise

shift(horizontal, vertical)[source]

Shifts rectangle by 2 axes simultaneously

Parameters:
  • horizontal

  • vertical

Return type:

BoxTag

Returns:

shifted rectangle

abstract to_dict()[source]

Return a dictionary representing the tag object

Return type:

dict

vshift(by)[source]

Shifts rectangle vertically

Parameters:

by – the amount by which the tag should be vertically shifted

Return type:

BoxTag

Returns:

shifted rectangle

property width: int | float

Width of the rectangle

property xcenter: float

Center of horizontal line of the rectangle

property ycenter: float

Center of vertical line of the rectangle