|
@@ -1,17 +1,10 @@
|
|
|
-from pylab import array, zeros, inv, dot, svd, shape, floor
|
|
|
|
|
|
|
+from pylab import array, zeros, inv, dot, svd, floor
|
|
|
from xml.dom.minidom import parse
|
|
from xml.dom.minidom import parse
|
|
|
-from Error import Error
|
|
|
|
|
from Point import Point
|
|
from Point import Point
|
|
|
from Character import Character
|
|
from Character import Character
|
|
|
from GrayscaleImage import GrayscaleImage
|
|
from GrayscaleImage import GrayscaleImage
|
|
|
from NormalizedCharacterImage import NormalizedCharacterImage
|
|
from NormalizedCharacterImage import NormalizedCharacterImage
|
|
|
|
|
|
|
|
-'''
|
|
|
|
|
- Creates a license plate object based on an XML file. The image should be
|
|
|
|
|
- placed in a folder 'images' the xml file in a folder 'xml'
|
|
|
|
|
-
|
|
|
|
|
- TODO: perhaps remove non required XML lookups
|
|
|
|
|
-'''
|
|
|
|
|
class LicensePlate:
|
|
class LicensePlate:
|
|
|
|
|
|
|
|
def __init__(self, folder_nr, file_nr):
|
|
def __init__(self, folder_nr, file_nr):
|
|
@@ -37,14 +30,14 @@ class LicensePlate:
|
|
|
N = max(y0, y1, y2, y3) - min(y0, y1, y2, y3)
|
|
N = max(y0, y1, y2, y3) - min(y0, y1, y2, y3)
|
|
|
|
|
|
|
|
matrix = array([
|
|
matrix = array([
|
|
|
- [x0, y0, 1, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
- [ 0, 0, 0, x0, y0, 1, 0, 0, 0],
|
|
|
|
|
- [x1, y1, 1, 0, 0, 0, -M*x0, -M*y1, -M],
|
|
|
|
|
- [ 0, 0, 0, x1, y1, 1, 0, 0, 0],
|
|
|
|
|
- [x2, y2, 1, 0, 0, 0, -M*x2, -M*y2, -M],
|
|
|
|
|
- [ 0, 0, 0, x2, y2, 1, -N*x2, -N*y2, -N],
|
|
|
|
|
- [x3, y3, 1, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
- [ 0, 0, 0, x3, y3, 1, -N*x3, -N*y3, -N]
|
|
|
|
|
|
|
+ [x0, y0, 1, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
+ [ 0, 0, 0, x0, y0, 1, 0, 0, 0],
|
|
|
|
|
+ [x1, y1, 1, 0, 0, 0, -M * x0, -M * y1, -M],
|
|
|
|
|
+ [ 0, 0, 0, x1, y1, 1, 0, 0, 0],
|
|
|
|
|
+ [x2, y2, 1, 0, 0, 0, -M * x2, -M * y2, -M],
|
|
|
|
|
+ [ 0, 0, 0, x2, y2, 1, -N * x2, -N * y2, -N],
|
|
|
|
|
+ [x3, y3, 1, 0, 0, 0, 0, 0, 0],
|
|
|
|
|
+ [ 0, 0, 0, x3, y3, 1, -N * x3, -N * y3, -N]
|
|
|
])
|
|
])
|
|
|
|
|
|
|
|
P = inv(self.get_transformation_matrix(matrix))
|
|
P = inv(self.get_transformation_matrix(matrix))
|
|
@@ -53,7 +46,9 @@ class LicensePlate:
|
|
|
for i in range(0, M):
|
|
for i in range(0, M):
|
|
|
for j in range(0, N):
|
|
for j in range(0, N):
|
|
|
or_coor = dot(P, ([[i],[j],[1]]))
|
|
or_coor = dot(P, ([[i],[j],[1]]))
|
|
|
- or_coor_h = or_coor[1][0] / or_coor[2][0], or_coor[0][0] / or_coor[2][0]
|
|
|
|
|
|
|
+ or_coor_h = (or_coor[1][0] / or_coor[2][0],
|
|
|
|
|
+ or_coor[0][0] / or_coor[2][0])
|
|
|
|
|
+
|
|
|
data[j][i] = self.pV(or_coor_h[0], or_coor_h[1])
|
|
data[j][i] = self.pV(or_coor_h[0], or_coor_h[1])
|
|
|
|
|
|
|
|
return data
|
|
return data
|
|
@@ -75,9 +70,7 @@ class LicensePlate:
|
|
|
def pV(self, x, y):
|
|
def pV(self, x, y):
|
|
|
image = self.image
|
|
image = self.image
|
|
|
|
|
|
|
|
- '''Get the value of a point x,y in the given image, where x and y are not
|
|
|
|
|
- necessary integers, so the value is interpolated from its neighbouring
|
|
|
|
|
- pixels.'''
|
|
|
|
|
|
|
+ #Get the value of a point (interpolated x, y) in the given image
|
|
|
if image.in_bounds(x, y):
|
|
if image.in_bounds(x, y):
|
|
|
x_low = floor(x)
|
|
x_low = floor(x)
|
|
|
x_high = floor(x + 1)
|
|
x_high = floor(x + 1)
|
|
@@ -161,4 +154,4 @@ class LicensePlate:
|
|
|
if corner.nodeName == "point":
|
|
if corner.nodeName == "point":
|
|
|
corners.append(Point(corner))
|
|
corners.append(Point(corner))
|
|
|
|
|
|
|
|
- return corners
|
|
|
|
|
|
|
+ return corners
|