COCO Labels Explained: The Annotation Format Behind Bounding-Box Detection

The COCO bounding box format stores each object as [x, y, width, height] in pixels from the top-left. Here is why it has no angle and where it breaks.

COCO Labels Explained: The Annotation Format Behind Bounding-Box Detection
Written by TechnoLynx Published on 11 Jul 2026

The COCO bounding box format stores every object instance as one record in an annotations array. Its bbox field holds four numbers, [x, y, width, height], in pixels, where (x, y) is the top-left corner of the box. The rectangle is aligned to the image axes, and its four values carry no angle. That is adequate for objects without many orientations. For rotated or closely packed objects, where orientation matters, the same four numbers also take in background and neighbouring objects. Those cases need an extra parameter, the angle theta, which NVIDIA’s toolkit adds to the COCO format.

How those labels then move through an evaluation harness is covered in our piece on how COCO annotations feed a perception eval. This page stays with the format itself.

What a COCO Annotation File Contains: Images, Categories and Bounding Boxes

A COCO annotation file is a single JSON document with three core sections. Each section has its own job:

  • images: one object per image, with id, file_name, width and height.
  • annotations: one object per object instance, with its own id, an image_id, a category_id, the bbox, segmentation polygons or RLE-encoded masks, and an area.
  • categories: one object per class, with id, name and supercategory.

Each annotation carries an image_id and a category_id alongside its own id. Every instance of an object in an image gets its own annotation object, so an image with twelve cars has twelve annotation records. A minimal record from the Ultralytics conversion guide looks like this:

{
  "images": [{ "id": 1, "file_name": "img_001.jpg", "width": 640, "height": 480 }],
  "annotations": [
    { "id": 1, "image_id": 1, "category_id": 1,
      "bbox": [100, 50, 200, 150], "area": 30000, "iscrowd": 0 }
  ]
}

The iscrowd flag marks an instance labelled as a COCO “crowd region” (0 by default, or 1). All of a dataset’s annotations sit in that one file, whereas YOLO gives each image its own text file.

How the COCO Bounding Box Format Stores a Box, and Why It Has No Angle

The COCO bbox is [x_min, y_min, width, height] in absolute pixel coordinates. The Albumentations documentation gives a concrete case: a box with corners at (98, 345) and (420, 462) is written in COCO as [98, 345, 322, 117], because the width is 420 − 98 and the height is 462 − 345.

NVIDIA’s write-up on rotated detection notes that most objects in natural images can be treated as axis-aligned and described by four parameters: xmin, ymin, width and height. The DOTA authors come at the same point from the other side. They note that axis-aligned boxes are typically used for natural scenes, and they label every DOTA instance with an oriented box instead.

COCO Compared with the Formats It Gets Confused With

Box conventions that look alike are a known source of conversion bugs. Here they are side by side:

Format Box values Units Origin of the reference point
COCO [x, y, width, height] Pixels Top-left corner
Pascal VOC [xmin, ymin, xmax, ymax] Pixels Two corner points
YOLO OBB Four corner points Normalised to 0-1  
COCO with theta (NVIDIA ODTK) [xmin, ymin, width, height, theta] Theta in radians Built from xmin, ymin, width, height, then rotated
MMRotate rotated box (x_center, y_center, width, height, theta) Theta in radians Box centre

Converting COCO to VOC is simple: xmin = x, ymin = y, xmax = x + width, ymax = y + height. Claru’s format reference calls this small difference one of the most common sources of bugs in detection pipelines.

What Happens to COCO Labels When Objects Are Rotated or Densely Packed?

A COCO box stays axis-aligned when the object rotates, so it no longer describes the object’s outline precisely. The box then covers more background, and in crowded scenes it also covers parts of neighbouring objects. NVIDIA’s example is a parking lot, where the box around one car also takes in nearby cars. Training on boxes like these makes it harder for the model to tell the objects of interest apart from the background.

Worked Example: A Square Rotated by 45°

Take a square with side s, rotated by 45°. Its tightest axis-aligned box has a side equal to the square’s diagonal, s√2, so the box area is 2s², twice the area of the object. NVIDIA notes that the gap is even larger for rectangles and other high-aspect-ratio objects.

On the ISPRS Potsdam aerial dataset, NVIDIA reports 0.77 precision and 0.76 recall for a rotated-box model, against 0.37 precision and 0.55 recall for an axis-aligned baseline. The rotated model’s average IoU was 0.60 against 0.29. The axis-aligned model sometimes produced several detections per vehicle, which the rotated model did not. NVIDIA also found negligible difference between the two models in latency and throughput. The DOTA authors saw the same pattern for densely packed, oriented objects: localisation precision with horizontal boxes was much lower than with oriented boxes, and many horizontal-box results were suppressed in post-processing.

These are aerial-imagery results. They show which way the effect goes and roughly how large it can be on that data, not what your line or scene will see. Whether rotation earns its cost on a particular workload is the subject of our parent piece on axis-aligned vs oriented bounding boxes and when rotated detection earns its cost.

How Do You Extend or Convert COCO Annotations for Oriented Boxes?

One way to extend COCO annotations for oriented boxes is to add one value, the angle. NVIDIA’s Object Detection Toolkit keeps the COCO object detection format and adds a theta parameter to each box. The box is first built from [xmin, ymin, width, height] and then rotated anticlockwise by theta radians. The toolkit’s conversion function has to be wrapped so that width and height stay positive and theta stays within either −π/2 to π/2 or −π to π. MMRotate defines a rotated box differently, as (x_center, y_center, width, height, theta) rotated about its centre, with theta in radians (theta = angle × π / 180).

The alternative is to store the box as the four corners of an arbitrary quadrilateral. DOTA annotates these quadrilaterals as four vertices in clockwise order, and for seven classes the first point normally marks the object’s “head”. The YOLO OBB label format also uses four corner points, normalised between 0 and 1. Internally, YOLO computes losses and outputs in xywhr (centre, width, height, rotation). Whether the model regresses four values or five is decided in the network, which our piece on detection head regression outputs covers.

The Angle Conventions That Bite

Three conventions differ between tools:

  1. Rotation direction. ODTK rotates anticlockwise, while Ultralytics measures the angle clockwise from the positive x-axis.
  2. Reference point. ODTK stores the box as top-left corner, width and height before rotation, while MMRotate and YOLO’s xywhr store the centre.
  3. Range and canonical form. Ultralytics treats an oriented box and its 180° rotation as identical, so rotation is modulo 180°, and it rewrites training labels so the width is the long edge. Its predictions are not rewritten this way, so xywhr output can report a width shorter than the height while the corner output is still correct. The parent article explains this angle ambiguity in full.

A rotated box at a multiple of 90° is just a horizontal box. Axis-aligned data therefore fits a rotated toolchain as boxes with theta set to zero. That is also where conversion stops: a standard COCO bbox holds four values and no angle. If the dataset also carries segmentation polygons, which COCO annotations can include, you can fit a minimum-area rotated rectangle to each polygon. Without polygons, getting oriented labels means annotating again, so deciding the label geometry before annotation starts costs less than deciding it afterwards. Deriving oriented boxes from promptable masks is covered in our piece on segmentation-derived oriented boxes.

Do Off-the-Shelf Detectors Expect COCO-Format Labels?

MMDetection and Detectron2 load COCO-format JSON, and Ultralytics documents a conversion from COCO. MMDetection documents a fixed set of keys that its COCO-format annotation files must contain. Detectron2 loads COCO datasets with load_coco_json, which fills in the class names automatically. Ultralytics trains on its own YOLO text format and provides a guide for converting COCO annotations into it.

Category ids go through a mapping step. Detectron2 keeps a thing_dataset_id_to_contiguous_id mapping from dataset class ids to contiguous ids in the range [0, number of classes). By default, Detectron2 also drops images with an empty annotations list from training, unless DATALOADER.FILTER_EMPTY_ANNOTATIONS is set otherwise.

For oriented boxes, the annotation gains an angle or four corners, and the evaluator needs rotated IoU. MMRotate describes replacing horizontal box annotations with rotated ones as the most notable difference between rotated and generic detection. TechnoLynx’s Computer Vision R&D team takes on this work when a production scene stops matching the training assumptions, choosing the label geometry, toolchain and evaluation together.

How COCO Category IDs and Box Geometry Are Used in IoU and mAP

COCO evaluation matches detections to ground truth per image and per category, then scores each match by IoU. In the reference computeIoU logic, ground truth and detections are indexed by [imgId, catId] when useCats is on, which is the default. A detection with the right box but the wrong category_id is therefore never compared with that object’s ground truth.

Box geometry then comes in through the IoU computation. The official COCO evaluation sweeps ten IoU thresholds from 0.5 to 0.95 in steps of 0.05 and allows at most 100 top-scoring detections per image. Object area is measured in pixels of the segmentation mask, not the box. COCO’s standard metrics are mean Average Precision and Average Recall.

For oriented boxes, IoU has to be computed on rotated rectangles. Detectron2’s RotatedCOCOeval checks whether boxes have five values and, if they do, switches to pairwise_iou_rotated. Otherwise it falls back to the classical COCO computation. The source notes two limits. It uses IoU only and ignores differences in angle, and it asserts that no ground truth is marked iscrowd, so crowd regions are not yet supported on the rotated path. Scoring an oriented detector with a horizontal-box evaluator quietly throws away the reason you labelled the angle in the first place.

What Should You Know About COCO Labels in Practice?

Before blaming the model, check these:

  • Corner or size? Is the third value a width or an xmax? Reading COCO as VOC, or VOC as COCO, shifts every box.
  • Pixels or normalised? COCO is in pixels and YOLO is normalised to 0-1, so a missed rescale squashes boxes into the corner of the image or pushes them out past its edges.
  • Top-left or centre? COCO measures from the top-left corner, while MMRotate’s rotated boxes and YOLO’s xywhr use the centre.
  • Augmentation in sync? After a flip or rotation, box coordinates have to transform with the pixels, or every box points at the wrong object.
  • Pixel-index offsets. Detectron2 adds 0.5 to COCO keypoint coordinates to turn discrete pixel indices into floating-point positions.
  • Category mapping. Do dataset ids map to the contiguous indices your framework expects, and does the evaluator use the same map?
  • Angle convention. Clockwise or anticlockwise, radians or degrees, top-left or centre pivot?

Choosing the Label Format for Your Production Geometry

The COCO bounding box format records only an upright rectangle, with no angle. If production objects stand upright and apart, stock COCO is a sound default, and the tooling built around it saves real effort. If they rotate, have a high aspect ratio or touch each other, settle the format at the feasibility stage, before annotation budget is spent. On an industrial line, that question sits inside the wider feasibility assessment for industrial computer vision inspection. Once the format is settled, the open question is economic: does the precision gained on your objects justify an oriented toolchain? Our analysis of when rotated detection earns its cost works through that decision.

FAQ

How Big Is the COCO Dataset?

According to Ultralytics’ documentation, COCO contains 330K images annotated across 80 object categories, and its Train2017 split has 118,287 images.

Does the COCO Format Support 3D Boxes?

No. Claru’s format reference lists COCO as 2D-only, while KITTI carries 3D boxes with seven degrees of freedom.