Helper class for converting values that represents bounding boxes into rectangles.
The class provides a static function to create bounding boxes as RectF
from different types of configurations.
Generally, a bounding box could be represented by 4 float values, but the values could be
interpreted in many ways. We now support 3 BoundingBoxUtil.Type
of configurations, and the order of
elements in each type is configurable as well.
Nested Classes
enum | BoundingBoxUtil.CoordinateType | Denotes if the coordinates are actual pixels or relative ratios. | |
enum | BoundingBoxUtil.Type | Denotes how a bounding box is represented. |
Public Methods
static List<RectF> |
convert(TensorBuffer tensor, int[] valueIndex, int boundingBoxAxis, BoundingBoxUtil.Type type, BoundingBoxUtil.CoordinateType coordinateType, int height, int width)
Creates a list of bounding boxes from a
TensorBuffer which represents bounding boxes. |
Inherited Methods
Public Methods
public static List<RectF> convert (TensorBuffer tensor, int[] valueIndex, int boundingBoxAxis, BoundingBoxUtil.Type type, BoundingBoxUtil.CoordinateType coordinateType, int height, int width)
Creates a list of bounding boxes from a TensorBuffer
which represents bounding boxes.
Parameters
tensor | holds the data representing some boxes. |
---|---|
valueIndex | denotes the order of the elements defined in each bounding box type. An empty
index array represent the default order of each bounding box type. For example, to denote
the default order of BOUNDARIES, {left, top, right, bottom}, the index should be {0, 1, 2,
3}. To denote the order {left, right, top, bottom}, the order should be {0, 2, 1, 3}.
The index array can be applied to all bounding box types to adjust the order of their corresponding underlying elements. |
boundingBoxAxis | specifies the index of the dimension that represents bounding box. The size of that dimension is required to be 4. Index here starts from 0. For example, if the tensor has shape 4x10, the axis for bounding boxes is likely to be 0. Negative axis is also supported: -1 gives the last axis and -2 gives the second, .etc. theFor shape 10x4, the axis is likely to be 1 (or -1, equivalently). |
type | defines how values should be converted into boxes. See BoundingBoxUtil.Type |
coordinateType | defines how values are interpreted to coordinates. See BoundingBoxUtil.CoordinateType |
height | the height of the image which the boxes belong to. Only has effects when coordinateType is BoundingBoxUtil.CoordinateType.RATIO |
width | the width of the image which the boxes belong to. Only has effects when coordinateType is BoundingBoxUtil.CoordinateType.RATIO |
Returns
- A list of bounding boxes that the
tensor
represents. All dimensions exceptboundingBoxAxis
will be collapsed with order kept. For example, giventensor
with shape {1, 4, 10, 2} andboundingBoxAxis = 1
, The result will be a list of 20 bounding boxes.
Throws
IllegalArgumentException | if size of bounding box dimension (set by boundingBoxAxis ) is not 4. |
---|---|
IllegalArgumentException | if boundingBoxAxis is not in (-(D+1), D) where
D is the number of dimensions of the tensor . |
IllegalArgumentException | if tensor has data type other than DataType.FLOAT32 .
|