Skip to contents

Converts bounding box data between three common formats: xyxy, xywh, and centerwh. Can also convert between relative and absolute measurements if image width and height is known.

Usage

bbox_convert(
  bbox,
  from,
  to,
  image = NULL,
  img_width = NULL,
  img_height = NULL,
  value_type = "absolute"
)

Arguments

bbox

character vector. Bounding box values.

from, to
  • from character vector. Bounding box format to convert from.

  • to character vector. Bounding box format to convert to.

  • Options: "xyxy", "xywh", and "centerwh"

image

character or magick-image. The image to extract width and height from. Only used if converting between value types (value_type is opposite of the provided bounding box). Value type of the input bounding box is inferred. Mutually exclusive with img_width and img_height.

img_width, img_height

numeric. The width and height of the image this bounding box belongs to. Only used if converting between value types (value_type is opposite of the provided bounding box). Value type of the input bounding box is inferred. Mutually exclusive mutually exclusive with image.

value_type

character. Type of values to use for the converted bounding box measures. Either "absolute" for pixel values or "relative" for scaled values.

Value

a numeric vector.