Keras 3 API 文档 / KerasCV / 边界框格式和工具 / 边界框工具 / 将边界框裁剪到提供的图像边界内

将边界框裁剪到提供的图像边界内

[source]

clip_to_image function

keras_cv.bounding_box.clip_to_image(
    bounding_boxes, bounding_box_format, images=None, image_shape=None
)

clips bounding boxes to image boundaries.

clip_to_image() clips bounding boxes that have coordinates out of bounds of an image down to the boundaries of the image. This is done by converting the bounding box to relative formats, then clipping them to the [0, 1] range. Additionally, bounding boxes that end up with a zero area have their class ID set to -1, indicating that there is no object present in them.

Arguments

  • bounding_boxes: bounding box tensor to clip.
  • bounding_box_format: the KerasCV bounding box format the bounding boxes are in.
  • images: list of images to clip the bounding boxes to.
  • image_shape: the shape of the images to clip the bounding boxes to.