Commit 82af5f4e authored by Jayke Meijer's avatar Jayke Meijer

Added comments to code.

parent 557bcdb2
......@@ -8,6 +8,8 @@ class Character:
self.filename = filename
def get_single_cell_feature_vector(self, neighbours=5):
"""Get the histogram of Local Binary Patterns over this entire
image."""
if hasattr(self, 'feature'):
return
......@@ -15,6 +17,7 @@ class Character:
self.feature = pattern.single_cell_features_vector()
def get_feature_vector(self, cell_size=None):
"""Get the concatenated histograms of Local Binary Patterns. """
pattern = LBP(self.image) if cell_size == None \
else LBP(self.image, cell_size)
......
from svmutil import svm_train, svm_problem, svm_parameter, svm_predict, \
svm_save_model, svm_load_model, RBF
class Classifier:
def __init__(self, c=None, gamma=None, filename=None, neighbours=3, \
verbose=0):
......
......@@ -22,20 +22,6 @@ class GrayscaleImage:
for x in xrange(self.data.shape[1]):
yield y, x, self.data[y, x]
#self.__i_x = -1
#self.__i_y = 0
#return self
#def next(self):
# self.__i_x += 1
# if self.__i_x == self.width:
# self.__i_x = 0
# self.__i_y += 1
# if self.__i_y == self.height:
# raise StopIteration
# return self.__i_y, self.__i_x, self[self.__i_y, self.__i_x]
def __getitem__(self, position):
return self.data[position]
......
......@@ -6,13 +6,9 @@ class Histogram:
self.max = max
def add(self, number):
#bin_index = self.get_bin_index(number)
#self.bins[bin_index] += 1
self.bins[number] += 1
def remove(self, number):
#bin_index = self.get_bin_index(number)
#self.bins[bin_index] -= 1
self.bins[number] -= 1
def get_bin_index(self, number):
......
......@@ -13,14 +13,16 @@ class NormalizedCharacterImage(GrayscaleImage):
self.blur = blur
self.gaussian_filter()
self.increase_contrast()
#self.increase_contrast()
self.height = height
self.resize()
def increase_contrast(self):
self.data -= self.data.min()
self.data = self.data.astype(float) / self.data.max()
# def increase_contrast(self):
# """Increase the contrast by performing a grayscale mapping from the
# current maximum and minimum to a range between 0 and 1."""
# self.data -= self.data.min()
# self.data = self.data.astype(float) / self.data.max()
def gaussian_filter(self):
GaussianFilter(self.blur).filter(self)
......
......@@ -80,6 +80,7 @@ def load_test_set(neighbours, blur_scale, verbose=0):
def generate_sets(neighbours, blur_scale, verbose=0):
"""Split the entire dataset into a trainingset and a testset."""
suffix = '_%s_%s' % (blur_scale, neighbours)
learning_set_file = 'learning_set%s.dat' % suffix
test_set_file = 'test_set%s.dat' % suffix
......
......@@ -125,33 +125,33 @@ def xml_to_LicensePlate(filename, save_character=None):
return LicensePlate(country, result_characters)
def get_corners(dom):
nodes = dom.getElementsByTagName("point")
corners = []
nodes = dom.getElementsByTagName("point")
corners = []
margin_y = 3
margin_x = 2
margin_y = 3
margin_x = 2
corners.append(
corners.append(
Point(get_coord(nodes[0], "x") - margin_x,
get_coord(nodes[0], "y") - margin_y)
)
)
corners.append(
corners.append(
Point(get_coord(nodes[1], "x") + margin_x,
get_coord(nodes[1], "y") - margin_y)
)
)
corners.append(
corners.append(
Point(get_coord(nodes[2], "x") + margin_x,
get_coord(nodes[2], "y") + margin_y)
)
)
corners.append(
corners.append(
Point(get_coord(nodes[3], "x") - margin_x,
get_coord(nodes[3], "y") + margin_y)
)
)
return corners
return corners
def get_coord(node, attribute):
return int(node.getAttribute(attribute))
return int(node.getAttribute(attribute))
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