BoundingBox<T>

Models & Types · AiDotNet.Augmentation.Image

Represents a bounding box annotation for object detection.

For Beginners

A bounding box is simply a rectangle around an object in an image, defined by its coordinates. Different systems use different ways to specify these coordinates (corners vs center, pixels vs percentages).

How It Works

Bounding boxes are rectangular regions that localize objects in images. This class supports multiple coordinate formats used by different frameworks and can convert between them.

Constructors

Constructor Summary
BoundingBox() Creates an empty bounding box.
BoundingBox(T x1, T y1, T x2, T y2, BoundingBoxFormat format, int classIndex) Creates a bounding box with the specified coordinates.

Properties

Property Summary
BoundingBoxFormat Format { get; set; } Gets or sets the current coordinate format.
IDictionary<string, object> Metadata { get; set; } Gets or sets additional metadata.
T Confidence { get; set; } Gets or sets the confidence score (if from a detector).
T X1 { get; set; } Gets or sets the X coordinate of the first point.
T X2 { get; set; } Gets or sets the X coordinate of the second point or width.
T Y1 { get; set; } Gets or sets the Y coordinate of the first point.
T Y2 { get; set; } Gets or sets the Y coordinate of the second point or height.
int ClassIndex { get; set; } Gets or sets the class label index.
int ImageHeight { get; set; } Gets or sets the image height (needed for normalized formats).
int ImageWidth { get; set; } Gets or sets the image width (needed for normalized formats).
string ClassName { get; set; } Gets or sets the class label name.

Methods

Method Summary
BoundingBox<T> Clone() Creates a deep copy of this bounding box.
ValueTuple<double, double, double, double> ToCXCYWH() Converts this bounding box to CXCYWH format.
ValueTuple<double, double, double, double> ToXYWH() Converts this bounding box to XYWH format.
ValueTuple<double, double, double, double> ToXYXY() Converts this bounding box to XYXY format.
ValueTuple<double, double, double, double> ToYOLO() Converts this bounding box to YOLO format (normalized).
bool IsValid() Checks if this bounding box is valid (has positive area).
double Area() Calculates the area of this bounding box.
double IoU(BoundingBox<T> other) Calculates the IoU (Intersection over Union) with another bounding box.
void Clip(int width, int height) Clips this bounding box to image boundaries.