项目作者: varunagrawal

项目描述 :
Python library for 2D/3D bounding boxes
高级语言: Python
项目地址: git://github.com/varunagrawal/bbox.git
创建时间: 2018-06-01T00:36:16Z
项目社区:https://github.com/varunagrawal/bbox

开源协议:MIT License

下载


bbox

bbox a Python library that is intended to ease the use of 2D and 3D bounding boxes in areas such as Object Detection by providing a set of flexible primitives and functions that are intuitive and easy to use out of the box.

Build Status
codecov

PyPI version
PyPI format


Say Thanks!

Features

2D Bounding Box

Easily work with bounding boxes using a simple class that abstracts and maintains various attributes.

  1. from bbox import BBox2D, XYXY
  2. # x, y, w, h
  3. box = BBox2D([0, 0, 32, 32])
  4. # equivalently, in (x1, y1, x2, y2) (aka two point format), we can use
  5. box = BBox2D([0, 0, 31, 31], mode=XYXY)
  6. print(box.x1, box.y1) # -> 0 0
  7. print(box.x2, box.y2) # -> 31 31
  8. print(box.height, box.width) # -> 32 32
  9. # Syntatic sugar for height and width
  10. print(box.h, box.w) # -> 32 32

Sequence of 2D bounding boxes

Most tasks involve dealing with multiple bounding boxes. This can also be handled conveniently with the BBox2DList class.

  1. bbl = BBox2DList(np.random.randint(10, 4),
  2. mode=XYWH)

The above snippet creates a list of 10 bounding boxes neatly abstracted into a convenient object.

Non-maximum Suppression

Need to perform non-maximum suppression? It is as easy as a single function call.

  1. from bbox.utils import nms
  2. # bbl -> BBox2DList
  3. # scores -> list/ndarray of confidence scores
  4. new_boxes = nms(bbl, scores)

Intersection over Union (Jaccard Index)

The Jaccard Index or IoU is a very useful metric for finding similarities between bounding boxes. bbox provides native support for this.

  1. from bbox.metrics import jaccard_index_2d
  2. box1 = BBox2D([0, 0, 32, 32])
  3. box2 = BBox2D([10, 12, 32, 46])
  4. iou = jaccard_index_2d(box1, box2)

We can even use the Jaccard Index to compute a distance metric between boxes as a distance matrix:

  1. from bbox.metrics import multi_jaccard_index_2d
  2. dist = 1 - multi_jaccard_index_2d(bbl, bbl)

3D Bounding Box

bbox also support 3D bounding boxes, providing convenience methods and attributes for working with them.