Skip to content

A utility script to transform bounding boxes along with the object image.

Notifications You must be signed in to change notification settings

007prateekd/bbox-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

bbox-utils

What

Just a small utility script that contains simple functions to

  • generate a binary mask and the corresponding bounding box coordinates of a subject in an image.
  • do simple transformations on an image (i.e. rotation, scaling, warping, overlaying, cropping, square resize) and modify the bounding box coordinates accordingly which could be quite challenging in some cases! For example, check this.

Why

While creating a synthetic dataset for an object detection use-case, I often ran into image transformations where I had a hard time modifying the corresponding bounding box coordinates with respect to the transformation applied. So, I created these helper functions which do the same. I have used PIL and OpenCV interchangably as both have some functionalities which are easier to use.

How

Run python main.py and the outputs would get saved to the images folder. If you set display = True here, then the outputs would also be displayed on the screen one by one. The only requirements are OpenCV and Pillow libraries. To run the script on your own image, change this path to where your image is. The functions have docstrings attached and can be used individually as per requirement.

Outputs

 Source image
 Binary mask of source image
 Overlaying source image on a white background
 Scaled image
 Rotated image
 Warped image
 Cropped image
 Resized square image
 Final bounding box coordinates