Commit 9536cb95 authored by unknown's avatar unknown

XML parser best wel af, maar moet nog mooier maken enzo

parent d11095b0
from Point import Point
# TODO cleanup the getElements stuff
class Character:
def __init__(self, character):
self.dom = character
self.value = self.get_node("char").firstChild.data
self.set_corners()
print self.corners
def set_corners(self):
corners = self.get_children("quadrangle")
self.corners = []
for corner in corners:
if corner.nodeName == "point":
self.corners.append(Point(corner))
def get_node(self, node, dom=None):
if not dom:
dom = self.dom
return dom.getElementsByTagName(node)[0]
def get_children(self, node, dom=None):
return self.get_node(node, dom).childNodes
\ No newline at end of file
from xml.dom.minidom import parse
from Error import Error
from Point import Point
from Character import Character
class LicensePlate:
def __init__(self, file_path):
try:
self.dom = parse(file_path)
except IOError:
Error("Incorrect file name given.")
return None
else:
properties = self.get_properties()
self.image = str(properties['uii']) + '.' + str(properties['type'])
self.width = properties['width']
self.height = properties['height']
info = self.set_plate()
def get_properties(self):
children = self.get_children("properties")
properties = {}
for child in children:
if child.nodeType == child.TEXT_NODE:
properties[child.nodeName] = child.data
elif child.nodeType == child.ELEMENT_NODE:
properties[child.nodeName] = child.firstChild.data
return properties
# TODO : create function for location / characters as they do the same
def set_plate(self):
children = self.get_children("plate") # most recent version
for child in children:
if child.nodeName == "regnum":
self.license_full = child.firstChild.data
elif child.nodeName == "identification-letters":
self.country = child.firstChild.data
elif child.nodeName == "location":
corners = self.get_children("quadrangle", child)
self.corners = []
for corner in corners:
if corner.nodeName == "point":
self.corners.append(Point(corner))
elif child.nodeName == "characters":
characters = child.childNodes
self.license_characters = []
for character in characters:
if character.nodeName == "character":
self.license_characters.append(Character(character))
else:
pass
#print child.nodeName
def get_node(self, node, dom=None):
if not dom:
dom = self.dom
return dom.getElementsByTagName(node)[0]
def get_children(self, node, dom=None):
return self.get_node(node, dom).childNodes
\ No newline at end of file
class Point:
def __init__(self, corner):
self.x = corner.getAttribute("x")
self.y = corner.getAttribute("y")
\ No newline at end of file
from LicensePlate import LicensePlate
'''
create new LicensePlate object:
i.e you can do
plate = LicensePlate("../XML/test.info") # some xml file from rein
now available:
plate.image
plate.width
plate.height
Are the entire image widht / height and image is the corresponding image file
provided by rein (i.e other folder somewhere)
plate.corners
plate.license_full # the entire license plate as a string so 2334AB
plate.characters # for each character from license_full a Character object
exists, kinda same as the license plate. You have a value
= the character / number
a corners -> i.e list of points (Point objects)
TODO had to go so this text is full of crap maybe, anyway enjoy
'''
plate = LicensePlate("../XML/test.info") # some xml file from rein
for corner in plate.corners:
print corner.x, corner.y
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment