Commit 4b1ffea7 authored by Jayke Meijer's avatar Jayke Meijer

Merge branch 'master' of github.com:taddeus/licenseplates

parents 5d21009d 957cba5c
......@@ -356,19 +356,23 @@ essential that you use the correct folder and subfolder naming scheme. The schem
is as follows:
\begin{enumerate}
\item A main folder called 'images' placed in the current directory as the src folder.
\item In the images folder there have to be three folders. Images, Infos and LearningSet.
\item The Images and Infos folder contain subfolders which are numbered ($0001$ to possibly $9999$).
\item In each of the subfolders the data (i.e the images or xml files) can be placed.
And have to be named $00991_XXXXX.ext$, where XXXXX can be $00000 to 99999$.
\item For loops in the script currently only go up to 9 subfolders, with a maximum
of containing 100 images or xml files. These numbers have to be adjusted if the scripts
are being used, but with a bigger dataset.
\item A main folder called `images' placed in the current directory as the
src folder.
\item In the images folder there have to be three folders. Images, Infos
and LearningSet.
\item The Images and Infos folder contain subfolders which are numbered
($0001$ to possibly $9999$).
\item In each of the subfolders the data (i.e the images or xml files) can
be placed. And have to be named $00991_XXXXX.ext$, where XXXXX can be
$00000 to 99999$.
\item For-loops in the script currently only go up to 9 subfolders, with a
maximum of containing 100 images or xml files. These numbers have to be
adjusted if the scripts are being used, but with a bigger dataset.
\end{enumerate}
It is ofcourse possible to use your own naming scheme. A search for the $filename$ variable will most
likely find the occurences where the naming scheme is implemented.
It is of course possible to use your own naming scheme. A search for the
$filename$ variable will most likely find the occurences where the naming
scheme is implemented.
\subsection*{\texttt{create\_characters.py}}
......@@ -385,16 +389,19 @@ likely find the occurences where the naming scheme is implemented.
\subsection*{\texttt{generate\_learning\_set.py}}
Usage of this script could be minimal, since you only need to extract the letters carefully
and succesfully once. Then other scripts in this list can use the extracted images. Most
likely the other scripts will use caching to speed up the system to. But in short, the script will create images of a single character based on a given dataset
of license plate images and corresponding xml files. If the xml files give correct
locations of the characters they can be extracted. The workhorse of this script is
$plate = xml_to_LicensePlate(filename, save_character=1)$. Where save_character is
an optional variable. If set it will save the image in the LearningSet folder and
pick the correct subfolder based on the character value. So if the XML says a character
is an 'A' it will be placed in the 'A' folder. These folders will be created automatically
if they do not exist yet.
Usage of this script could be minimal, since you only need to extract the
letters carefully and succesfully once. Then other scripts in this list can use
the extracted images. Most likely the other scripts will use caching to speed
up the system to. But in short, the script will create images of a single
character based on a given dataset of license plate images and corresponding
xml files. If the xml files give correct locations of the characters they can
be extracted. The workhorse of this script is $plate =
xml_to_LicensePlate(filename, save_character=1)$. Where
\texttt{save\_character} is an optional variable. If set it will save the image
in the LearningSet folder and pick the correct subfolder based on the character
value. So if the XML says a character is an 'A' it will be placed in the 'A'
folder. These folders will be created automatically if they do not exist yet.
\subsection*{\texttt{load\_learning\_set.py}}
......
......@@ -3,7 +3,7 @@ from cPickle import load, dump
DATA_FOLDER = 'data/'
IMAGES_FOLDER = '../images/LearningSet/'
IMAGES_FOLDER = '../images/characters/'
RESULTS_FOLDER = 'results/'
......
......@@ -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
\ No newline at end of file
get_attr(p[3], "x") - x, get_attr(p[3], "y") + 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