Bounding box annotation from segmentation maps/id maps for computer vision.

Sometimes you want to generate synthetic data for training computer vision models. It is often easy to generate segmentation maps or class ID maps where objects in the image become uniform colours, simply using AOVs within 3D modelling programs, such as Maya, or by using substitute shaders in Unity or Unreal (or swapping out the material for one which just presents a uniform colour).

For many standard computer vision models, we require bounding box annotations, often given in the form of x1, y1, x2, y2, where these represent the coordinates of the bottom left and top right corners of the bounding box.

Here is a python script for converting from a segmentation map to bounding box annotations in a csv file. It also shows the bounding box annotation and you can save the bounding boxes also as images.

Please head over to my GitHub to check it out.

Example segmentation map.

Example segmentation map.

Bounding box output.

Bounding box output.