Box

class box.Box(coords=None)[source]

Bases: object

Detection box class

Parameters

coords (tuple (default=None)) – Box Coordinates as (x, y, w, h)

Example

>>> import pylab as plt
>>> from matplotlib.patches import Rectangle
>>>
>>> b1 = Box((.5, .3, .2, .1))
>>> x_1, y_1, w_1, h_1 = b1.box
>>> left_1, top_1, right_1, bottom_1 = b1.coords
>>>
>>> print('Box1: {}'.format(b1))
>>>
>>> b2 = Box((.4, .5, .2, .5))
>>> x_2, y_2, w_2, h_2 = b2.box
>>> left_2, top_2, right_2, bottom_2 = b2.coords
>>>
>>> print('Box2: {}'.format(b2))
>>>
>>> print('Intersection: {:.3f}'.format(b1.intersection(b2)))
>>> print('Union: {:.3f}'.format(b1.union(b2)))
>>> print('IOU: {:.3f}'.format(b1.iou(b2)))
>>> print('rmse: {:.3f}'.format(b1.rmse(b2)))
>>>
>>> plt.figure()
>>> axis = plt.gca()
>>> axis.add_patch(Rectangle(xy=(left_1, top_1),
>>>                          width=w_1, height=h_1,
>>>                          alpha=.5, linewidth=2, color='blue'))
>>> axis.add_patch(Rectangle(xy=(left_2, top_2),
>>>                          width=w_2, height=h_2,
>>>                          alpha=.5, linewidth=2, color='red'))
property area

Compute the are of the box

Returns

area – Area of the current box.

Return type

float

property box

Get the box coordinates

Returns

coords – Box coordinates as (x, y, w, h)

Return type

tuple

property center

In the current storage the x,y are the center of the box

Returns

center – Center of the current box.

Return type

tuple

property coords

Return box coordinates in clock order (left, top, right, bottom)

Returns

coords – Coordinates as (left, top, right, bottom)

Return type

tuple

property dimensions

In the current storage the w,h are the dimensions of the rectangular box

Returns

dims – Dimensions of the current box as (width, height).

Return type

tuple

intersection(other)[source]

Common area between boxes

Parameters

other (Box) – 2nd term of the evaluation

Returns

intersection – Intersection area of two boxes

Return type

float

iou(other)[source]

Intersection over union

Parameters

other (Box) – 2nd term of the evaluation

Returns

iou – Intersection over union between boxes

Return type

float

rmse(other)[source]

Root mean square error of the boxes

Parameters

other (Box) – 2nd term of the evaluation

Returns

rmse – Root mean square error of the boxes

Return type

float

union(other)[source]

Full area without intersection

Parameters

other (Box) – 2nd term of the evaluation

Returns

union – Union area of the two boxes

Return type

float