|
|
@@ -6,6 +6,8 @@ from Character import Character
|
|
|
from GrayscaleImage import GrayscaleImage
|
|
|
from NormalizedCharacterImage import NormalizedCharacterImage
|
|
|
from LicensePlate import LicensePlate
|
|
|
+from data import IMAGES_FOLDER
|
|
|
+
|
|
|
|
|
|
# Gets the character data from a picture with a license plate
|
|
|
def retrieve_data(plate, corners):
|
|
|
@@ -38,6 +40,7 @@ def retrieve_data(plate, corners):
|
|
|
|
|
|
return data
|
|
|
|
|
|
+
|
|
|
def get_transformation_matrix(matrix):
|
|
|
# Get the vector p and the values that are in there by taking the SVD.
|
|
|
# Since D is diagonal with the eigenvalues sorted from large to small
|
|
|
@@ -48,6 +51,7 @@ def get_transformation_matrix(matrix):
|
|
|
|
|
|
return inv(array([[p[0],p[1],p[2]], [p[3],p[4],p[5]], [p[6],p[7],p[8]]]))
|
|
|
|
|
|
+
|
|
|
def pV(image, x, y):
|
|
|
#Get the value of a point (interpolated x, y) in the given image
|
|
|
if not image.in_bounds(x, y):
|
|
|
@@ -67,6 +71,7 @@ def pV(image, x, y):
|
|
|
+ image[x_low , y_high] / x_y * a * d \
|
|
|
+ image[x_high, y_high] / x_y * c * d
|
|
|
|
|
|
+
|
|
|
def xml_to_LicensePlate(filename, save_character=None):
|
|
|
plate = GrayscaleImage('../images/Images/%s.jpg' % filename)
|
|
|
dom = parse('../images/Infos/%s.info' % filename)
|
|
|
@@ -100,10 +105,10 @@ def xml_to_LicensePlate(filename, save_character=None):
|
|
|
data = retrieve_data(plate, corners)
|
|
|
image = NormalizedCharacterImage(data=data)
|
|
|
result.append(Character(value, corners, image, filename))
|
|
|
-
|
|
|
+
|
|
|
if save_character:
|
|
|
character_image = GrayscaleImage(data=data)
|
|
|
- path = "../images/LearningSet/%s" % value
|
|
|
+ path = IMAGES_FOLDER + value
|
|
|
image_path = "%s/%d_%s.jpg" % (path, i, filename.split('/')[-1])
|
|
|
|
|
|
if not exists(path):
|
|
|
@@ -114,15 +119,19 @@ def xml_to_LicensePlate(filename, save_character=None):
|
|
|
|
|
|
return LicensePlate(country, result)
|
|
|
|
|
|
+
|
|
|
def get_node(node, tag):
|
|
|
return by_tag(node, tag)[0].firstChild.data
|
|
|
|
|
|
+
|
|
|
def by_tag(node, tag):
|
|
|
return node.getElementsByTagName(tag)
|
|
|
|
|
|
+
|
|
|
def get_attr(node, attr):
|
|
|
return int(node.getAttribute(attr))
|
|
|
|
|
|
+
|
|
|
def get_corners(dom):
|
|
|
p = by_tag(dom, "point")
|
|
|
|
|
|
@@ -134,4 +143,4 @@ def get_corners(dom):
|
|
|
return get_attr(p[0], "x") - x, get_attr(p[0], "y") - y,\
|
|
|
get_attr(p[1], "x") + x, get_attr(p[1], "y") - y,\
|
|
|
get_attr(p[2], "x") + x, get_attr(p[2], "y") + y,\
|
|
|
- get_attr(p[3], "x") - x, get_attr(p[3], "y") + y
|
|
|
+ get_attr(p[3], "x") - x, get_attr(p[3], "y") + y
|