https://github.com/devrimcavusoglu/pybboxes
Light weight toolkit for bounding boxes providing conversion between bounding box types and simple computations.
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.8%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Light weight toolkit for bounding boxes providing conversion between bounding box types and simple computations.
Basic Info
Statistics
- Stars: 153
- Watchers: 3
- Forks: 15
- Open Issues: 0
- Releases: 10
Topics
Metadata Files
README.md
PyBboxes
Light weight toolkit for bounding boxes providing conversion between bounding box types and simple computations. Supported bounding box types (italicized text indicates normalized values):
- albumentations : Albumentations Format
- [x-tl, y-tl, x-br, y-br] (Normalized VOC Format) Top-left coordinates & Bottom-right coordinates
- coco : COCO (Common Objects in Context)
- [x-tl, y-tl, w, h] Top-left corner & width & height
- fiftyone : FiftyOne
- [x-tl, y-tl, w, h] (Normalized COCO Format) Top-left coordinates & width & height
- voc : Pascal VOC
- [x-tl, y-tl, x-br, y-br] Top-left coordinates & Bottom-right coordinates
- yolo : YOLO
- [x-c, y-c, w, h] Center coordinates & width & height
Glossary
- tl: top-left
- br: bottom-right
- h: height
- w: width
- c: center
News 🔥
- 2024/10/07 - Annotations are supported for YOLO, COCO and VOC formats.
Roadmap 🛣️
Important Notice
Support for Python<3.8 will be dropped starting version `0.2` though the development for Python3.6 and Python3.7 may continue where it will be developed under version `0.1.x` for future versions. This may introduce; however, certain discrepancies and/or unsupported operations in the `0.1.x` versions. To fully utilize and benefit from the entire package, we recommend using Python3.8 at minimum (`Python>=3.8`).
Installation
Through pip (recommended),
pip install pybboxes
or build from source,
git clone https://github.com/devrimcavusoglu/pybboxes.git
cd pybboxes
python setup.py install
Bounding Boxes
You can easily create bounding box as easy as
```python from pybboxes import BoundingBox
mycocobox = [98, 345, 322, 117] cocobbox = BoundingBox.fromcoco(*mycocobox) # <98 345 322 117 | Image: (?x?)>
or alternatively
cocobbox = BoundingBox.fromarray(mycocobox)
```
Out of Bounds Boxes
Pybboxes supports OOB boxes, there exists a keyword strict in both Box classes (construction) and in functional
modules. When strict=True, it does not allow out-of-bounds boxes to be constructed and raises an exception, while
it does allow out-of-bounds boxes to be constructed and used when strict=False. Also, there is a property is_oob
that indicates whether a particular bouding box is OOB or not.
Important Note that, if the return value for is_oob is None, then it indicates that OOB status is unknown
(e.g. image size required to determine, but not given). Thus, values None and False indicates different information.
```python from pybboxes import BoundingBox
imagesize = (640, 480) mycocobox = [98, 345, 580, 245] # OOB box for 640x480 cocobbox = BoundingBox.fromcoco(*mycocobox, imagesize=image_size) # Exception
ValueError: Given bounding box values is out of bounds. To silently skip out of bounds cases pass 'strict=False'.
cocobbox = BoundingBox.fromcoco(*mycocobox, imagesize=imagesize, strict=False) # No Exception cocobbox.isoob # True ```
If you want to allow OOB, but still check OOB status, you should use strict=False and is_oob where needed.
Conversion
With the BoundingBox class the conversion is as easy as one method call.
```python from pybboxes import BoundingBox
mycocobox = [98, 345, 322, 117] cocobbox = BoundingBox.fromcoco(*mycocobox) # <98 345 322 117 | Image: (?x?)> vocbbox = cocobbox.tovoc() # <98 345 420 462 | Image: (?x?)> vocbboxvalues = cocobbox.tovoc(returnvalues=True) # (98, 345, 420, 462) ```
However, if you try to make conversion between two bounding boxes that require scaling/normalization it'll give an error
```python from pybboxes import BoundingBox
mycocobox = [98, 345, 322, 117] cocobbox = BoundingBox.fromcoco(*mycocobox) # <98 345 322 117 | Image: (?x?)>
yolobbox = cocobbox.to_yolo() # this will raise an exception
You need to set imagesize for cocobbox and then you're good to go
cocobbox.imagesize = (640, 480) yolobbox = cocobbox.to_yolo() # <0.4047 0.8406 0.5031 0.2437 | Image: (640x480)> ```
Image size associated with the bounding box can be given at the instantiation or while using classmethods e.g
from_coco().
```python from pybboxes import BoundingBox
mycocobox = [98, 345, 322, 117] cocobbox = BoundingBox.fromcoco(*mycocobox, image_size=(640, 480)) # <98 345 322 117 | Image: (640x480)>
no longer raises exception
yolobbox = cocobbox.to_yolo() # <0.4047 0.8406 0.5031 0.2437 | Image: (640x480)> ```
Box operations
Box operations now available as of v0.1.0.
```python from pybboxes import BoundingBox
mycocobox = [98, 345, 322, 117] mycocobox2 = [90, 350, 310, 122] cocobbox = BoundingBox.fromcoco(mycocobox, imagesize=(640, 480)) cocobbox2 = BoundingBox.from_coco(mycocobox2, image_size=(640, 480))
iou = cocobbox.iou(cocobbox2) # 0.8117110631149508 areaunion = cocobbox + cocobbox2 # 41670 | alternative way: cocobbox.union(cocobbox2) totalarea = cocobbox.area + cocobbox2.area # 75494 (not union) intersectionarea = cocobbox * cocobbox2 # 33824 | alternative way: cocobbox.intersection(cocobbox2) firstbboxdiff = cocobbox - cocobbox2 # 3850 secondbboxdiff = cocobbox2 - cocobbox # 3996 bboxratio = cocobbox / cocobbox2 # 0.9961396086726599 (not IOU) ```
Functional
Note: functional computations are moved under pybboxes.functional starting with the version 0.1.0. The only
exception is that convert_bbox() which still can be used by importing pybboxes only (for backward compatibility).
Conversion
You are able to convert from any bounding box type to another.
```python import pybboxes as pbx
cocobbox = (1,2,3,4) # COCO Format bbox as (x-tl,y-tl,w,h) vocbbox = (1,2,3,4) # Pascal VOC Format bbox as (x-tl,y-tl,x-br,y-br) pbx.convertbbox(cocobbox, fromtype="coco", totype="voc") # (1, 2, 4, 6) pbx.convertbbox(vocbbox, fromtype="voc", totype="coco") # (1, 2, 2, 2) ```
Some formats require image width and height information for scaling, e.g. YOLO bbox (resulting coordinates are rounded to 2 decimals to ease reading).
```python import pybboxes as pbx
vocbbox = (1,2,3,4) # Pascal VOC Format bbox as (x-tl,y-tl,x-br,y-br) pbx.convertbbox(vocbbox, fromtype="voc", totype="yolo", imagesize=(28, 28)) # (0.07, 0.11, 0.07, 0.07) ```
Computation
You can also make computations on supported bounding box formats.
```python import pybboxes.functional as pbf
cocobbox = (1,2,3,4) # COCO Format bbox as (x-tl,y-tl,w,h) vocbbox = (1,2,3,4) # Pascal VOC Format bbox as (x-tl,y-tl,x-br,y-br) pbf.computearea(cocobbox, bboxtype="coco") # 12 pbf.computearea(vocbbox, bboxtype="voc") # 4 ```
Annotation file conversion
pybboxes now supports the conversion of annotation file(s) across different annotation formats. (yolo, voc and coco are currently supported)
This is a 3 step process.
1. Instantiate the Annotations class
```python from pybboxes.annotations import Annotations
anns = Annotations(annotation_type='yolo') ```
Important you have to explicitly declare annotation_type beforehand. post declaration, you will be only able to load annotation in declared format but you will be able to export to other annotation formats.
2. Load the annotations file
After you have instantiated the Annotations class declaring annotation_type, you can now load the annotations using appropriate method of the Annotations class.
2.1 Load from yolo
```python from pybboxes.annotations import Annotations
anns = Annotations(annotation_type='yolo')
anns.loadfromyolo(labelsdir='./labels', imagesdir='./images', classes_file='./classes.txt') ```
As yolo normalizes the bounding box metadata, path to corresponding images directory must be provided (via images_dir) so that physical dimension of image data can be inferred.
Also, path to classes_file (usually classes.txt) should be provided that lists all the class labels that is used for the annotation. Without this, pybboxes will fail to assign appropriate class labels when converting across different annotations format.
2.2 Load from voc
```python from pybboxes.annotations import Annotations
anns = Annotations(annotation_type='voc')
anns.loadfromvoc(labels_dir='./labels') ```
2.3 Load from coco
```python from pybboxes.annotations import Annotations
anns = Annotations(annotation_type='coco')
anns.loadfromcoco(json_path='./validation.json') ```
3. Saving annotations to different format
3.1 Saving annotations to yolo format
As every image data has its own corresponding annotation file in yolo format, you have to provide path to export_dir where all the annotation files will be written.
```python from pybboxes.annotations import Annotations
anns = Annotations(annotation_type='coco') # just for the demonstration purpose
anns.loadfromcoco(json_path='./validation.json') # we could have loaded the annotation data from other format as well
anns.saveasyolo(export_dir='./labels')
``
This will create all the required annotation files (in yolo format) in given directory. Additionally, it will also createclasses.txt` in the given folder which will list all the class labels used for the annotation.
3.2 Saving annotations to voc format
Just like yolo format, in voc format, every image data has also its own corresponding annotation file. So, you have to provide path to export_dir where all the annotation files will be written.
```python from pybboxes.annotations import Annotations
anns = Annotations(annotation_type='coco') # just for the demonstration purpose
anns.loadfromcoco(json_path='./validation.json') # we could have loaded the annotation data from other format as well
anns.saveasvoc(export_dir='./labels') ```
3.3 Saving annotations to coco format
To export annotations in coco format, you just have to provide name (or path) of the output file (in json format) via export_file.
```python from pybboxes.annotations import Annotations
anns = Annotations(annotation_type='voc') # just for the demonstration purpose
anns.loadfromvoc(labels_dir='./labels') # we could have loaded the annotation data from other format as well
anns.saveascoco(export_file='./validation.json') ```
Contributing
Installation
Install the package as follows, which will set you ready for the development mode.
shell
pip install -e .[dev]
Tests
To tests simply run.
python -m tests.run_tests
Code Style
To check code style,
python -m tests.run_code_style check
To format codebase,
python -m tests.run_code_style format
License
Licensed under the MIT License.
Owner
- Name: Devrim
- Login: devrimcavusoglu
- Kind: user
- Company: @obss
- Repositories: 2
- Profile: https://github.com/devrimcavusoglu
Deep Learning Engineer | MS CS @ METU How deep is your learn ?
GitHub Events
Total
- Watch event: 8
- Fork event: 1
Last Year
- Watch event: 8
- Fork event: 1
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| devrimcavusoglu | d****u@g****m | 36 |
| Harsh Raj | h****g@g****m | 10 |
| fatih | 3****n | 5 |
| Gaurav Parajuli | 5****i | 1 |
| Dean Wetherby | 1****e | 1 |
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 11
- Total pull requests: 22
- Average time to close issues: 3 months
- Average time to close pull requests: 13 days
- Total issue authors: 4
- Total pull request authors: 6
- Average comments per issue: 2.27
- Average comments per pull request: 0.55
- Merged pull requests: 21
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 3
- Average time to close issues: N/A
- Average time to close pull requests: 6 days
- Issue authors: 0
- Pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 1.0
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- devrimcavusoglu (6)
- kadirnar (2)
- harshraj22 (2)
- dean-wetherby-simplisafe (1)
Pull Request Authors
- devrimcavusoglu (18)
- fcakyon (2)
- harshraj22 (1)
- gauravparajuli (1)
- kadirnar (1)
- dean-wetherby-simplisafe (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- pypi 123,661 last-month
- Total docker downloads: 527
-
Total dependent packages: 11
(may contain duplicates) -
Total dependent repositories: 34
(may contain duplicates) - Total versions: 13
- Total maintainers: 1
pypi.org: pybboxes
Light Weight Toolkit for Bounding Boxes
- Homepage: https://github.com/devrimcavusoglu/pybboxes
- Documentation: https://pybboxes.readthedocs.io/
- License: MIT
-
Latest release: 0.2.0
published over 1 year ago
Rankings
Maintainers (1)
conda-forge.org: pybboxes
- Homepage: https://github.com/devrimcavusoglu/pybboxes
- License: MIT
-
Latest release: 0.1.5
published over 3 years ago
Rankings
Dependencies
- actions/cache v1 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite
- numpy *