Convert bounding boxes from Coco to Pascal_VOC to Yolo and back.

Christian Bernecker
2 min readJan 14, 2022

This article describes the differences between the bounding boxes format Coco, Pascal_VOC and Yolo Style and provides Code-Snippets about converting from one to another.

What are bounding boxes?

Bounding boxes are rectangles used to surround objects in images. They are often used in object detection. There are multiple formats of bounding boxes (Coco, Yolo, Pascal). Each format uses its specific representation of bounding boxes coordinates. The following picture illustrates a bounding box.

Bounding Box — Object / Face Detection

In the next chapter I will explain the specific representations of each bounding box standard. Afterwards you will find code snippets to convert from one format to another.

Coco:

Format [x_min, y_min, width, height]

The coordinates (x_min, y_min) are the top-left corner along with the width and height of the bounding box.

Pascal_VOC :

Format: [x_min, y_min, x_max, y_max]

x_min and y_min are coordinates of the top-left corner and x_max and y_max are coordinates of bottom-right corner of the bounding box.

Yolo:

Format: [x_center, y_center, width, height]

x_center and y_center are the normalized coordinates of the centre of the bounding box. The width and height are the normalized length. To convert YOLO in Coco or Pascal or vice versa it is important to have the size of the image to calculate the normalization.

Code Snippets

That is probably the reason why you are here

Converting Coco to Pascal_voc

Converting Coco to Yolo

Converting Pascal_voc to Coco

Converting Pascal_voc to Yolo

Converting Yolo to Coco

Converting Yolo to Pascal_voc

Questions & Comments?

Ask in the comments and I’ll answer soon as possible.

--

--

Christian Bernecker

IT Architect | Data Scientist | Software Developer | Data Driven Investor