This repository has been archived by the owner on Jan 17, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.py
61 lines (44 loc) · 1.69 KB
/
Bootstrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import re
from PIL import Image
from Utils.ArgParser import ArgParser
from Classifier.DescriptorGenerator import DescriptorGenerator
from Pipeline.Pipeline import Pipeline
from Utils.ReadWrite import ReadWrite
from Training.Trainer import Trainer
from Shared.Borg import Borg
from Shared.Parameters import Parameters
class Bootstrap(Borg):
def __init__(self):
args = ArgParser.parse()
Parameters.set_parameters({
'mode' : args.mode,
'input_image' : args.input_image,
'training_set' : args.training_set,
'model_path' :args.model_path
})
def run(self):
p = Parameters().get_parameters()
if p['mode'] == 'training':
Trainer().train()
elif p['mode'] == 'classification':
img = np.asarray(Image.open(p['input_image']).convert('L'))
data = Pipeline().run(img)
desc_i = DescriptorGenerator.generate_descriptor(data)
descs = ReadWrite.read(p['model_path'])
min_diff = float("inf")
letter_actu = "_"
for i in descs:
nw_letter = i[0]
nw_desc = [float(j) for j in re.findall(r"[\d.]+", i)]
dist_actu = DescriptorGenerator.distance(desc_i, nw_desc)
if dist_actu < min_diff:
min_diff = dist_actu
letter_actu = nw_letter
print(letter_actu)
else:
img = np.asarray(Image.open(p['input_image']).convert('L'))
res = Pipeline().run(img)
print(res[1])