Bounding Box
A bounding box is the rectangle that marks where an object sits in an image. Covers xyxy, xywh and YOLO formats, labeling, and rotated and 3D boxes.
A bounding box is the smallest axis-aligned rectangle that encloses an object in an image or video frame, described by four numbers. It is the unit of output in object detection: a detector returns one box per object together with a class label and a confidence score, and annotators draw the same boxes on training data to teach the model. A box locates an object and gives its rough size without tracing its shape, which makes boxes quick to label and cheap to predict.
Coordinate Formats#
Image coordinates start at the top-left corner, with x growing to the right and y growing downward. Every box format stores four numbers, but datasets and libraries disagree on which four, and mixing them up silently shifts or stretches every box.
- Corners (xyxy): the top-left corner (x1, y1) and the bottom-right corner (x2, y2), in pixels. PASCAL VOC annotations and most drawing and IoU functions use this form.
- COCO format: the top-left corner followed by the width and height, [x, y, width, height], in pixels.
- YOLO format: the box center followed by its width and height, each divided by the image width or height so every value falls between 0 and 1. Ultralytics YOLO models such as YOLO26 train from one text file per image with one row per object: the class index, then x_center, y_center, width, and height.
Normalized coordinates survive resizing: an image can be scaled to any training resolution without rewriting its labels, because the boxes are stored as fractions of the image size.
from ultralytics import YOLO
# Load a pretrained YOLO26 nano detector
model = YOLO("yolo26n.pt")
# Detect objects and take the boxes from the first image
results = model("https://ultralytics.com/images/bus.jpg")
boxes = results[0].boxes
# The same first box in four formats
print(boxes.xyxy[0]) # corners in pixels
print(boxes.xywh[0]) # center, width, height in pixels
print(boxes.xyxyn[0]) # corners divided by image width and height
print(boxes.xywhn[0]) # center and size divided by image size, as in YOLO labelsAll four lines describe one rectangle. The normalized versions divide the pixel values by the 810 × 1080 size of the image, and xywh is measured from the box center, so it differs from COCO's top-left xywh.
How Detectors Predict Boxes#
A detector predicts boxes as regression outputs at many positions in the image. Earlier designs predicted offsets from predefined anchor boxes of fixed sizes and aspect ratios, and anchor-free detectors predict the distances from a grid point to the four box edges directly. Training compares predicted and labeled boxes with losses based on intersection over union (IoU), and because neighboring positions predict overlapping boxes for the same object, non-maximum suppression (NMS) removes the duplicates at inference.
Labeling Bounding Boxes#
A detector learns to draw boxes the way its labels are drawn, so data annotation guidelines decide box quality. Good guidelines ask for boxes that touch the visible edges of each object, for every instance of every class to be labeled, since an unlabeled object teaches the model that it is background, and for a fixed rule on occluded and truncated objects, such as boxing only the visible part. Evaluation inherits the same rules, because a prediction is scored by its IoU with the labeled box.
Bounding Boxes vs. Other Region Types#
- Oriented bounding boxes (OBB): a fifth value, the rotation angle, lets the box turn to fit angled objects such as ships or vehicles in aerial images with much less background inside.
- Instance segmentation: a per-pixel mask that outlines each object's exact shape.
- Keypoints: individual landmark points, such as body joints for pose estimation.
- 3D bounding boxes: cuboids in real-world space, usually described by seven numbers: the center (x, y, z), the length, width, and height in meters, and a heading angle.










