Oriented Bounding Box – Annotation


This article describes the annotation of Oriented Bounding Boxes.
Oriented Bounding Boxes are different from normal Bounding Boxes in that the angle of the rectangle can be set freely. On the other hand, in a normal Bounding Box, the angle of the rectangle is always parallel to the XY axis.

In the figure below, the left side is a normal Bounding Box and the right side is an Oriented Bounding Box. The normal Bounding Box is enclosed with a lot of margins or other objects, while the Oriented Bounding Box is able to enclose only the pills.



Ubuntu 20.04.


Set up the annotation tool. For the annotation tool, we use labelImg2. There is a similar tool, labelImg_OBB, but it did not work correctly.

sudo apt update sudo apt-get install pyqt5-dev-tools python3-pip git clone https://github.com/chinakook/labelImg2 cd labelImg2 python3 -m pip install lxml
Code language: Bash (bash)

Sample Data

As an annotation example, download the image to the data folder of labelImage2 and prepare a class file in which only “car” exists.

wget https://img.freepik.com/premium-photo/aerial-view-of-many-colorful-cars-parked-on-parking-lot-in-evening_127089-18411.jpg?w=1800 -O data/car-parking.jpg echo car > data/classes.txt
Code language: Bash (bash)


Launch labelImage2.

python3 labelImg.py data/ data/classes.txt data/
Code language: Bash (bash)

The first argument data/ specifies the image data directory. The second argument data/classes.txt is the class file. The third argument data/ specifies the directory in which to store the annotation results.

When you launch labelImage2, you will see the following.

For annotations, select Edit > Create RotatedRBox or press “e” on the keyboard to create an Oriented Bounding Box. Drag left to enclose the box and right to rotate it.

You can duplicate a box by pressing Ctrl+D. You can also use Ctrl+mouse wheel to zoom in and out.

Press Ctrl+s to save the annotation file. The final result will look like this.

In this annotation example, there was no need to select a class because there was only one class type, “car,” but when annotating multiple classes, it is necessary to select the appropriate class.

Annotation File

You can see that the annotation file data/car-parking.xml has been created. The following is an excerpt from data/car-parking.xml

<object> <name>car</name> <pose>Unspecified</pose> <truncated>0</truncated> <difficult>0</difficult> <robndbox> <cx>343.0944</cx> <cy>715.3419</cy> <w>123.0101</w> <h>59.9565</h> <angle>0.459784</angle> </robndbox> <extra/> </object> <object> <name>car</name> <pose>Unspecified</pose> <truncated>0</truncated> <difficult>0</difficult> <robndbox> <cx>375.0944</cx> <cy>659.3419</cy> <w>123.0101</w> <h>59.9565</h> <angle>0.459784</angle> </robndbox> <extra/> </object>
Code language: HTML, XML (xml)

There are same number of <object>...</object> as Oriented Bounding Boxes created in the annotation work. There are <cx>, <cy>, <w>, <h>, <angle> and in <robndbox>...</robndbox>, which are the x coordinate of the center of the Orineted Bounding Box, the y coordinate of the center, width, height, and angle, respectively.

That’s all.