Skip to main content

xmlobj is simple utility to map xml file to python object

Project description

Description

xmlobj is simple utility to map xml file to python object

xmlobj also allows you to add functionality to mapped object by adding mixin class

A Simple Example

from pathlib import Path

from PIL import Image, ImageDraw

from xmlobj.xmlmapping import get_xml_obj


class DrawBoxesMixin:
    def draw_box(self, image) -> Image.Image:
        p1 = (self.object.bndbox.xmin, self.object.bndbox.ymin)
        p2 = (self.object.bndbox.xmax, self.object.bndbox.ymax)
        img_draw = ImageDraw.Draw(image)
        img_draw.text(p1, self.object.name, align="left")
        img_draw.rectangle([p1, p2])
        return image


if __name__ == "__main__":
    pascal_annotation = Path("samples/000027.xml")
    img_file = "samples/000027.jpg"
    img = Image.open(img_file)
    obj = get_xml_obj(pascal_annotation, mixin_cls=DrawBoxesMixin)
    rendered_img = obj.draw_box(img.copy())
    rendered_img.show()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xmlobj-1.0.0.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

xmlobj-1.0.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page