Commit 17913d43 authored by Fabien's avatar Fabien

De license plate ingekort en ook het sorteren maar weggehaald omdat we het...

De license plate ingekort en ook het sorteren maar weggehaald omdat we het neit gebruiken. Wel een check of de versie correct is en een letter 4 punten krijgt
parent c333da85
from LocalBinaryPatternizer import LocalBinaryPatternizer from LocalBinaryPatternizer import LocalBinaryPatternizer
class Character: class Character:
def __init__(self, value, corners, image): def __init__(self, value, corners, image, filename=None):
self.value = value self.value = value
self.corners = corners self.corners = corners
self.image = image self.image = image
self.filename = filename
def get_feature_vector(self): def get_feature_vector(self):
pattern = LocalBinaryPatternizer(self.image) pattern = LocalBinaryPatternizer(self.image)
......
...@@ -10,77 +10,8 @@ class LicensePlate: ...@@ -10,77 +10,8 @@ class LicensePlate:
def __init__(self, folder_nr, file_nr): def __init__(self, folder_nr, file_nr):
filename = '%04d/00991_%04d%02d' % (folder_nr, folder_nr, file_nr) filename = '%04d/00991_%04d%02d' % (folder_nr, folder_nr, file_nr)
self.dom = parse('../images/Infos/%s.info' % filename)
properties = self.get_properties()
self.image = GrayscaleImage('../images/Images/%s.jpg' % filename) self.image = GrayscaleImage('../images/Images/%s.jpg' % filename)
self.width = int(properties['width']) self.read_xml(filename)
self.height = int(properties['height'])
self.read_xml()
def are_corners_sorted(corners):
'''Check if points are sorted clockwise, starting in the left-top
corner.'''
x0, y0 = corners[0].to_tuple()
x1, y1 = corners[1].to_tuple()
x2, y2 = corners[2].to_tuple()
x3, y3 = corners[3].to_tuple()
return x0 < x1 and y1 <= y2 and x2 >= x3 and y3 > y0
def sort_corners(corners):
'''Sort the corners clockwise, starting in the left-top corner.'''
tuples = []
output = []
for point in corners:
tuples.append(point.to_tuple())
bot1 = (0, 0)
bot2 = (0, 0)
top1 = None
top2 = None
# Get bottom points (where the y value is the largest). The top points
# are the points that are not a bottom point.
for tup in tuples:
if tup[1] > bot1[1] or tup[1] > bot2[1]:
if top1 == None:
top1 = bot2
else:
top2 = bot2
if tup[1] > bot1[1]:
bot2 = bot1
bot1 = tup
else:
bot2 = tup
else:
if top1 == None:
top1 = tup
else:
top2 = tup
# First point is the smallest x-value top point, second is the other
# top point
if top1[0] < top2[0]:
output.append(Point(top1[0], top1[1]))
output.append(Point(top2[0], top2[1]))
else:
output.append(Point(top2[0], top2[1]))
output.append(Point(top1[0], top1[1]))
# Third point is the bottom point with the largest x-value, fourth is
# the other bottom point
if bot1[0] > bot2[0]:
output.append(Point(bot1[0], bot1[1]))
output.append(Point(bot2[0], bot2[1]))
else:
output.append(Point(bot2[0], bot2[1]))
output.append(Point(bot1[0], bot1[1]))
return output
# sets the entire license plate of an image # sets the entire license plate of an image
def retrieve_data(self, corners): def retrieve_data(self, corners):
...@@ -153,68 +84,40 @@ class LicensePlate: ...@@ -153,68 +84,40 @@ class LicensePlate:
return 0 return 0
# Testing purposes def read_xml(self, filename):
def show(self): dom = parse('../images/Infos/%s.info' % filename)
from pylab import imshow, show self.characters = []
imshow(self.data, cmap="gray")
show()
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 version = dom.getElementsByTagName("current-version")[0].firstChild.data
def read_xml(self): info = dom.getElementsByTagName("info")
children = self.get_children("plate") # most recent version
for child in children: for i in info:
if child.nodeName == "regnum": if version == i.getElementsByTagName("version")[0].firstChild.data:
self.license_full = child.firstChild.data
elif child.nodeName == "identification-letters":
self.country = child.firstChild.data
elif child.nodeName == "location":
self.corners = self.get_corners(child)
elif child.nodeName == "characters":
nodes = child.childNodes
self.characters = [] self.country = i.getElementsByTagName("identification-letters")[0].firstChild.data
characters = i.getElementsByTagName("characters")[0].childNodes
for character in nodes: for character in characters:
if character.nodeName == "character": if character.nodeName == "character":
value = self.get_node("char", character).firstChild.data value = character.getElementsByTagName("char")[0].firstChild.data
corners = self.get_corners(character) corners = self.get_corners(character)
data = self.retrieve_data(corners)
image = NormalizedCharacterImage(data=data)
self.characters.append(Character(value, corners, image)) if not len(corners) == 4:
else: break
pass
def get_node(self, node, dom=None): data = self.retrieve_data(corners)
if not dom: image = NormalizedCharacterImage(data=data)
dom = self.dom
return dom.getElementsByTagName(node)[0] self.characters.append(Character(value, corners, image, filename))
def get_children(self, node, dom=None): break
return self.get_node(node, dom).childNodes
def get_corners(self, child): def get_corners(self, dom):
nodes = self.get_children("quadrangle", child) nodes = dom.getElementsByTagName("point")
corners = [] corners = []
for corner in nodes: for node in nodes:
if corner.nodeName == "point": corners.append(Point(node))
corners.append(Point(corner))
return corners return corners
\ No newline at end of file
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