svkcore.shapes

svkcore.shapes.shapes

Common shapes for object detection

class svkcore.shapes.shapes.Box(obj, dtype=None)[source]

Bases: Shape

Box of 2d. Record top_left and bottom_right corner position of box.

area()[source]

Calculate box area

Returns:

box area

Return type:

np.float

bsize()[source]

Size of box

Returns:

box size in format np.array([width, height])

Return type:

np.ndarray

center()[source]

Center point of a box

Returns:

center point

Return type:

Point

classmethod from_cxywh(cxywh)[source]

Create box from format [min-x, min-y, max-x, max-y]

Returns:

converted box in format [min-x, min-y, max-x, max-y]

Return type:

Box

scale(scale)[source]

Scale box

Parameters:

scale – scale factor

Returns:

a scaled box

Return type:

Box

to_cxywh()[source]

Convert box format to [center-x, center-y, width, height]

Returns:

converted box in format [center-x, center-y, width, height]

Return type:

np.ndarray

to_mask(size=None)[source]

Convert box to mask

Parameters:

size

Returns:

to_polygon()[source]

Convert box to polygon from top_left and across top_right, bot_right and end to bot_left

Returns:

the converted polygon

Return type:

Polygon

class svkcore.shapes.shapes.Boxes(obj, dtype=None)[source]

Bases: Shape

Collection of Box

areas()[source]

Calculate boxes areas

Returns:

boxes areas

Return type:

np.ndarray

bsize()[source]

Sizes of boxes

Returns:

boxes sizes in format np.array([[width, height], …])

Return type:

np.ndarray

center()[source]

Center points of a boxes

Returns:

center points

Return type:

Points

classmethod from_cxywh(cxywh)[source]

Create box from format [min-x, min-y, max-x, max-y]

Returns:

converted box in format [min-x, min-y, max-x, max-y]

Return type:

Boxes

scale(scale)[source]

Scale boxes

Parameters:

scale – scale factor

Returns:

a scaled boxes

Return type:

Boxes

to_cxywh()[source]

Convert box format to [center-x, center-y, width, height]

Returns:

converted boxes in format [center-x, center-y, width, height]

Return type:

np.ndarray

class svkcore.shapes.shapes.Line(obj, dtype=None)[source]

Bases: Points

Line of 2d

length()[source]

Calculate the length of a continuous line

Returns:

the line length

Return type:

np.float

class svkcore.shapes.shapes.Mask(obj, dtype=None)[source]

Bases: Shape

Mask of 2d

area()[source]

Calculate mask area

Returns:

mask area

Return type:

np.float

bounding_box()[source]

Get the minimum bounding box of this mask

Returns:

then minimum bounding box of this mask

Return type:

Box

swap()[source]

Swap mask shape coordinate order from x-y to y-x

Returns:

swapped this mask

Return type:

Mask

class svkcore.shapes.shapes.Point(obj, dtype=None)[source]

Bases: Shape

Point of 2d

class svkcore.shapes.shapes.Points(obj, dtype=None)[source]

Bases: Point

Collection of Points

bounding_box()[source]

Get the minimum bounding box a collection of points

Returns:

bounding box

Return type:

Box

class svkcore.shapes.shapes.Polygon(obj, dtype=None)[source]

Bases: Shape

Polygon of 2d

area()[source]

Calculate polygon area use mask area calculate

Returns:

polygon area

Return type:

np.float

bounding_box()[source]

Get the minimum bounding box of this polygon

Returns:

bounding box

Return type:

Box

to_mask(size=None)[source]

Convert polygon to mask

Parameters:

size – the final mask size. Default is None means use the minimum size that can overlap this mask

Returns:

converted mask from polygon

Return type:

np.ndarray

class svkcore.shapes.shapes.Shape(obj, dtype=None)[source]

Bases: object

Base class for object detection shapes. Wrap a numpy.array object and add specified operations for each type shape.

numpy()[source]

Get numpy data

Returns:

shape data

Return type:

np.ndarray

order = 0
swap()[source]

Swap this shape coordinate order from x-y to y-x

Returns:

swapped this shape

Return type:

Shape