BoundingBoxUtil

public final 类 BoundingBoxUtil

用于将表示边界框的值转换为矩形的辅助类。

该类提供了一个静态函数,用于根据不同类型的配置将边界框创建为 RectF

通常,边界框可以由 4 个浮点值表示,但这些值可以以多种方式解释。我们现在支持 3 个 BoundingBoxUtil.Type 配置,并且每种类型中元素的顺序也可以配置。

嵌套类

枚举 BoundingBoxUtil.CoordinateType 表示坐标是实际像素还是相对比率。
枚举 BoundingBoxUtil.Type 表示边界框的表示方式。

公共方法

static List<RectF>
convert(TensorBuffer tensor, int[] valueIndex, int boundsBoxAxis, BoundingBoxUtil.Type type, BoundingBoxUtil.CoordinateType CoordinateType, int height, int width)
根据表示边界框的 TensorBuffer 创建边界框列表。

继承的方法

公共方法

public static List<RectF> convert (TensorBuffer tensor, int[] valueIndex, int boundsBoxAxis, BoundingBoxUtil.Type type, BoundingBoxUtil.CoordinateType CoordinateType, int height, int width)

根据表示边界框的 TensorBuffer 创建边界框列表。

参数
张量 存储表示某些框的数据。
valueIndex 表示每种边界框类型中定义的元素的顺序。空索引数组表示每种边界框类型的默认顺序。例如,如需表示 BOUNDARIES, {left, top, right, bottom} 的默认顺序,索引应为 {0, 1, 2, 3}。如需指明顺序 {left, right, top, bottom},顺序应该是 {0, 2, 1, 3}。

索引数组可应用于所有边界框类型,以调整其对应底层元素的顺序。

boundingBoxAxis 指定表示边界框的维度的索引。该维度的大小必须为 4。此处的索引从 0 开始。例如,如果张量的形状为 4x10,则边界框的轴可能是 0。系统也支持负轴:-1 表示最后一个轴,-2 表示第二个轴,依此类推。对于形状 10x4,该轴可能是 1(或等效的 -1)。
类型 定义如何将值转换为方块。查看BoundingBoxUtil.Type
coordinateType 定义如何将值解释为坐标。查看BoundingBoxUtil.CoordinateType
高度 方框所属的图片的高度。仅当 coordinateTypeBoundingBoxUtil.CoordinateType.RATIO 时才有效
宽度 方框所属的图片的宽度。仅当 coordinateTypeBoundingBoxUtil.CoordinateType.RATIO 时才有效
返回
  • tensor 所表示的边界框列表。除 boundingBoxAxis 之外的所有维度都将收起,并保留顺序。例如,假设 tensor 的形状为 {1, 4, 10, 2} 和 boundingBoxAxis = 1,结果将是一个包含 20 个边界框的列表。
抛出
IllegalArgumentException 如果边界框尺寸(通过 boundingBoxAxis 设置)大小不是 4,则返回此值。
IllegalArgumentException 如果 boundingBoxAxis 不在 (-(D+1), D) 中,其中 Dtensor 的维度数。
IllegalArgumentException 如果 tensor 的数据类型不是 DataType.FLOAT32