此页面由 AI 自动翻译。查看英文原版
最后更新

本页目录

  • 类
  • Mosaic4
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包
最后更新
Python API: luxonis_ml.data.augmentations.custom.mosaic

类

Mosaic4

基于批次的增强,创建四张图像的马赛克。该变换以确定的 2×2 网格排列四张图像:
第 1 列第 2 列
12
34
图像可以有不同的大小,但它们必须具有相同的通道数。结果将围绕马赛克中心裁剪为 out_width 乘以 out_height,并在需要时用指定的填充值进行填充。
https://raw.githubusercontent.com/luxonis/luxonis-ml/58fb10adc38a393640b9dc889fdefd1db81f9900/luxonis_ml/data/augmentations/media/mosaic4.png
Mosaic4 增强的一个示例。

方法

init
Python
1def __init__(height: int | None = None, width: int | None = None, image_fill_value: float | list[int] | list[float] | None = None, mask_fill_value: float | list[int] | list[float] | None = None, p: float = 0.5, out_height: int | None = None, out_width: int | None = None, value: float | list[int] | list[float] | None = None, mask_value: float | list[int] | list[float] | None = None):
创建 Mosaic4 增强。参数
  • height (int | None): 输出图像高度。
  • width (int | None): 输出图像宽度。
  • image_fill_value (float | list[int] | list[float] | None): 图像的填充值。
  • mask_fill_value (float | list[int] | list[float] | None): 掩码的填充值。
  • p (float): 应用变换的概率。
  • out_height (int | None):
  • out_width (int | None):
  • value (float | list[int] | list[float] | None):
  • mask_value (float | list[int] | list[float] | None):
引发
  • ValueError: 如果解析的输出高度或宽度缺失或不大于 0。
apply
Python
1def apply(image_batch: list[np.ndarray], x_crop: int, y_crop: int, **_) -> np.ndarray:
将马赛克增强应用于一批图像。参数
  • image_batch (list[np.ndarray]): 要变换的图像。每张图像的形状应为 (H, W, C) 或 (H, W)。
  • x_crop (int): 裁剪起始点的 X 坐标。
  • y_crop (int): 裁剪起始点的 Y 坐标。
  • **_
返回
  • np.ndarray: 形状为 (Hout, Wout, C) 或 (Hout, Wout) 的单张图像。
apply_to_bboxes
Python
1def apply_to_bboxes(bboxes_batch: list[np.ndarray], image_shapes: list[tuple[int, int]], x_crop: int, y_crop: int, **_) -> np.ndarray:
将马赛克增强应用于一批边界框。参数
  • bboxes_batch (list[np.ndarray]): 要变换的边界框。
  • image_shapes (list[tuple[int, int]]): 原始图像形状。
  • x_crop (int): 裁剪起始点的 X 坐标。
  • y_crop (int): 裁剪起始点的 Y 坐标。
  • **_
返回
  • np.ndarray: 变换后的边界框。
apply_to_instance_mask
Python
1def apply_to_instance_mask(masks_batch: list[np.ndarray], x_crop: int, y_crop: int, **_) -> np.ndarray:
将马赛克增强应用于一批实例分割掩码。参数
  • masks_batch (list[np.ndarray]): 要变换的掩码。每个掩码的形状应为 (H, W, N),其中 N 是实例数。
  • x_crop (int): 裁剪起始点的 X 坐标。
  • y_crop (int): 裁剪起始点的 Y 坐标。
  • **_
返回
  • np.ndarray: 形状为 (Hout, Wout, N) 的单个实例掩码。
apply_to_keypoints
Python
1def apply_to_keypoints(keypoints_batch: list[np.ndarray], image_shapes: list[tuple[int, int]], x_crop: int, y_crop: int, **_) -> np.ndarray:
将马赛克增强应用于一批关键点。参数
  • keypoints_batch (list[np.ndarray]): 要变换的关键点。
  • image_shapes (list[tuple[int, int]]): 原始图像形状。
  • x_crop (int): 裁剪起始点的 X 坐标。
  • y_crop (int): 裁剪起始点的 Y 坐标。
  • **_
返回
  • np.ndarray: 变换后的关键点。
apply_to_mask
Python
1def apply_to_mask(mask_batch: list[np.ndarray], x_crop: int, y_crop: int, out_height: int, out_width: int, **_) -> np.ndarray:
将马赛克增强应用于一批语义分割掩码。参数
  • mask_batch (list[np.ndarray]): 要变换的掩码。每个掩码的形状应为 (H, W, C) 或 (H, W)。
  • x_crop (int): 裁剪起始点的 X 坐标。
  • y_crop (int): 裁剪起始点的 Y 坐标。
  • out_height (int): 输出掩码的预期高度。
  • out_width (int): 输出掩码的预期宽度。
  • **_
返回
  • np.ndarray: 形状为 (Hout, Wout, C) 或 (Hout, Wout) 的单个分割掩码。
generate_random_crop_center
Python
1def generate_random_crop_center(self) -> tuple[int, int]:
在马赛克图像大小的边界内生成一个随机裁剪中心。
get_params_dependent_on_data
Python
1def get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) -> dict[str, Any]:
获取依赖于目标的参数。参数
  • params (dict[str, Any]): 现有增强参数。
  • data (dict[str, Any]): 输入数据。
返回
  • dict[str, Any]: 从输入目标派生的参数。