Polygon Pascal VOC Writer
A simple python module to generate Pascal VOC XML image annotation files.
Currently only supports bounding-boxes and polygons.
Improved upon AndrewCarterUK's Pascal VOC Writer.
Installation
$ pip install polygon-pascalvoc-writer
Importing:
from polygon_pascalvoc_writer import VocWriter
Table of Contents
Example Execution
For a single image
back to Contents
Write annotation for myImage.png (width: 100, height: 150) :
from polygon_pascalvoc_writer import VocWriter
images_dir = "dir/images/"
annotations_dir = "dir/annotations/"
image_name = "myImage.png"
writer = VocWriter(images_dir, annotations_dir, image_name)
# Rectangular bounding box
box_name = "myLabelBox"
xmin, ymin, xmax, ymax = 1, 2, 3, 4
writer.addBndBox(box_name, xmin, ymin, xmax, ymax)
# 1st polygon
polygon_1_name = "myPolygon"
vertices_1 = [
[1, 2],
[3, 4],
[5, 6]
]
writer.addPolygon(polygon_1_name, vertices_1)
# 2nd polygon
polygon_2_name = "myPolygon"
vertices_2 = [
[10, 20],
[30, 40],
[50, 60]
]
writer.addPolygon(polygon_2_name, vertices_2)
# Write to XML file in VOC format
writer.save()
Output file, dir/annotation/myImage.xml :
<annotation>
<folder>images</folder>
<filename>myImage.png</filename>
<path>absolutePathTo/dir/images/myImage.png</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>100</width>
<height>150</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>myLabelBox</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>1</xmin>
<ymin>2</ymin>
<xmax>3</xmax>
<ymax>4</ymax>
</bndbox>
</object>
<object>
<name>myPolygon</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<polygon>
<x1>1</x1>
<y1>2</y1>
<x2>3</x2>
<y2>4</y2>
<x3>5</x3>
<y3>6</y3>
</polygon>
<bndbox>
<xmin>1</xmin>
<ymin>2</ymin>
<xmax>5</xmax>
<ymax>6</ymax>
</bndbox>
</object>
<object>
<name>myPolygon</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<polygon>
<x1>10</x1>
<y1>20</y1>
<x2>30</x2>
<y2>40</y2>
<x3>50</x3>
<y3>60</y3>
</polygon>
<bndbox>
<xmin>10</xmin>
<ymin>20</ymin>
<xmax>50</xmax>
<ymax>60</ymax>
</bndbox>
</object>
</annotation>
For a folder of images
back to Contents
Write annotation for image1.png and image2.png :
from polygon_pascalvoc_writer import VocWriter
images_dir = "dir/images/"
annotations_dir = "dir/annotations/"
writer = VocWriter(images_dir, annotations_dir, "")
list_of_annotations = [
{
"image_name": "image1.png",
"polygons": [
[
[1, 2],
[3, 4],
[5, 6]
],
[
[10, 20],
[30, 40],
[50, 60]
]
]
},
{
"image_name": "image2.png",
"polygons": [
[
[7, 8],
[9, 10],
[11, 12]
],
[
[70, 80],
[90, 100],
[110, 120]
]
]
}
]
for annotation in list_of_annotations:
# Clears the label data, then sets the image with
# name matching annotation["image_name"] as the current working image.
# Doesn't save the label data. Saving is done by writer.save()
writer.nextImage(annotation["image_name"])
for polygon_vertices in annotation["polygons"]:
writer.addPolygon("polygon_name", polygon_vertices)
# Write to XML file in VOC format
writer.save()
Resulting directories:
dir
├── images
| ├── image1.png
| └── image2.png
└── annotations
├── image1.xml
├── image2.xml
Metadata
Release files for polygon-pascalvoc-writer 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| polygon-pascalvoc-writer-1.0.5.tar.gz | 4.5 kB | Without provenance | Details for polygon-pascalvoc-writer-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| polygon_pascalvoc_writer-1.0.5-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for polygon_pascalvoc_writer-1.0.5-py2.py3-none-any.whl |
Total release size: 10.0 kB
Release files / polygon-pascalvoc-writer-1.0.5.tar.gz
| Download URL | polygon-pascalvoc-writer-1.0.5.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
25fa23bd5ae09304a26dc3953a6a9069dc0df9c0b49cab52ba1f5c7e19f9aacb
|
|
BLAKE2b-256 checksum How to use checksums |
837bda7c21ca60d946ae58142a687adc9ec8f793409ff5616c57151a2a192b63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
|
Release files / polygon_pascalvoc_writer-1.0.5-py2.py3-none-any.whl
| Download URL | polygon_pascalvoc_writer-1.0.5-py2.py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
4d8cff1966f12d5b9b299af6cc108933f02972ba787bd045d35591d424eef0e9
|
|
BLAKE2b-256 checksum How to use checksums |
3cae48e750d859d6d259cfc2b925f4a7f28ac832ed4922f0f685261cff5c8978
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12
|
Security for polygon-pascalvoc-writer 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.