Skip to content
This repository has been archived by the owner on Jan 17, 2019. It is now read-only.

Commit

Permalink
structure finished
Browse files Browse the repository at this point in the history
  • Loading branch information
LeC-D committed Nov 24, 2018
1 parent b53df62 commit 3f06144
Show file tree
Hide file tree
Showing 30 changed files with 139 additions and 54 deletions.
59 changes: 33 additions & 26 deletions Projet/Bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@
import numpy as np
from PIL import Image

from EdgeDetection.EdgeDetection import EdgeDetection
from Clipping.Clipping import Clipping
from Utils.ArgParser import ArgParser
from Classifier.DescriptorGenerator import DescriptorGenerator
from Pipeline.Pipeline import Pipeline

class Bootstrap:
def __init__(self):
#self.iimProc =
#self.fingDetec =
self.edgeDetec = EdgeDetection()
self.clip = Clipping()
#self.classifier =
#self.boundTrac =

def run(self):
#if
from Training.Trainer import Trainer

#else:
#processedImage =
img = Image.open('./asl_alphabet_test/C3_test.jpeg').convert('L')
image = np.asarray(img)
from Shared.Borg import Borg
from Shared.Parameters import Parameters

edges = self.edgeDetec.detect_edges(image)

clippedEdges = self.clip.clip(edges)
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
})

test2 = np.asarray(clippedEdges)
test = Image.fromarray(test2)
plot = plt.imshow(test)
plt.show()
#plot = plt.imshow(clippedEdges)
#plt.show()
def run(self):
p = Parameters().get_parameters()

if p['mode'] == 'training':
Trainer().train()

elif p['mode'] == 'classification':
print('hello')

else:
img = np.asarray(Image.open('./asl_alphabet_test/U_test.jpg').convert('L'))
res = Pipeline().run(img)
test2 = np.asarray(res)
test = Image.fromarray(test2)
plot = plt.imshow(test)
plt.show()




Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions Projet/Classifier/DescriptorGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class DescriptorGenerator:

@staticmethod
def generate_origin_descriptor():
return 0

@staticmethod
def generate_descriptor(data):
return 0
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion Projet/Clipping/Clipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def clip(self, edgesImage):
self.image = np.asarray(edgesImage)
y1 = self.calculY1()
y2 = self.calculY2()
print('y1', y1, 'y2', y2)
clipping_level = max(y1, y2)
for i in range(clipping_level, len(self.image)):
zeros = np.zeros(len(self.image[i])).astype('uint8')
Expand Down
Binary file modified Projet/Clipping/__pycache__/Clipping.cpython-35.pyc
Binary file not shown.
12 changes: 3 additions & 9 deletions Projet/EdgeDetection/EdgeDetection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

class EdgeDetection:
def __init__(self):
self.threshold_1 = 80
self.threshold_2 = 80
self.threshold_1 = 10
self.threshold_2 = 5

def calc_offset(self, angle):

Expand Down Expand Up @@ -140,10 +140,4 @@ def detect_edges(self, image):

updated_mask = self.hysterisis(mask, image_maxima)

return self.apply_mask(updated_mask, image_maxima)






return self.apply_mask(updated_mask, image_maxima)
Binary file modified Projet/EdgeDetection/__pycache__/EdgeDetection.cpython-35.pyc
Binary file not shown.
3 changes: 0 additions & 3 deletions Projet/ImageProcessing/__init__.py

This file was deleted.

3 changes: 1 addition & 2 deletions Projet/Main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from Bootstrap import Bootstrap

boot = Bootstrap()
boot.run()
Bootstrap().run()
17 changes: 17 additions & 0 deletions Projet/Pipeline/Pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from EdgeDetection.EdgeDetection import EdgeDetection
from Clipping.Clipping import Clipping
from BoundaryTracing.BoudaryTracing import BoundaryTracing

from Shared.Borg import Borg

class Pipeline(Borg):
def __init__(self):
self.edgeDetec = EdgeDetection()
self.clip = Clipping()
self.boundTrac = BoundaryTracing()

def run(self, input):
edges_image = self.edgeDetec.detect_edges(input)
clipped_image = self.clip.clip(edges_image)

return clipped_image
Binary file added Projet/Pipeline/__pycache__/Pipeline.cpython-35.pyc
Binary file not shown.
4 changes: 4 additions & 0 deletions Projet/Shared/Borg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Borg:
_shared_state = {}
def __init__(self):
self.__dict__ = self._shared_state
10 changes: 10 additions & 0 deletions Projet/Shared/Parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Parameters:
parameters = {}

@staticmethod
def set_parameters(new_parameters):
Parameters.parameters.update(new_parameters)

@staticmethod
def get_parameters():
return Parameters.parameters
File renamed without changes.
Binary file added Projet/Shared/__pycache__/Borg.cpython-35.pyc
Binary file not shown.
Binary file added Projet/Shared/__pycache__/Parameters.cpython-35.pyc
Binary file not shown.
Binary file added Projet/Shared/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
45 changes: 45 additions & 0 deletions Projet/Training/Trainer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from PIL import Image
from os import listdir
import numpy as np

from Utils.ReadWrite import ReadWrite
from Classifier.DescriptorGenerator import DescriptorGenerator
from Pipeline.Pipeline import Pipeline

from Shared.Borg import Borg
from Shared.Parameters import Parameters

class Trainer(Borg):
def __init__(self):
p = Parameters.get_parameters()
self.path_data = p['training_set']
self.path_model = p['model_path']

def train(self):
actu_letter = None

training_data_files = listdir(self.path_data)
print(training_data_files)

centroid_actu_descriptor = DescriptorGenerator.generate_origin_descriptor()

count = 0

for i in range(0, len(training_data_files)):
if training_data_files[i].split('_') == actu_letter:
count = count + 1

img = np.asarray(Image.open(self.path_data + training_data_files[i]).convert('L'))
data = Pipeline().run(img)

centroid_actu_descriptor = centroid_actu_descriptor + DescriptorGenerator.generate_descriptor(data)

else:
centroid_actu_descriptor = centroid_actu_descriptor / count
ReadWrite.write(self.path_model, actu_letter + ' ' + centroid_actu_descriptor)

actu_letter = training_data_files[i].split('_')
centroid_actu_descriptor = DescriptorGenerator.generate_origin_descriptor()
count = 0


File renamed without changes.
Binary file not shown.
Binary file added Projet/Training/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
17 changes: 4 additions & 13 deletions Projet/Utils/ArgParser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
from Shared.Parameters import Parameters


class ArgParser:
Expand All @@ -8,16 +7,8 @@ def parse():
parser = argparse.ArgumentParser(
description='Relay between Oronos rocket & clients (PC/tablets).')

parser.add_argument('-b', '--baudrate', type=int,
help='Baudrate of the serial port')
parser.add_argument('-c', '--connector_type',
help='Data source', choices=['serial', 'simulation'], default='simulation')
parser.add_argument('-f', '--connector_file',
help='Connector type. COM serial port or CSV file')
parser.add_argument('-s', '--server', type=int, default=3000,
help='Activates a server listening on a certain port')
parser.add_argument('-r', '--rocket', default='11_valkyrieM2.xml',
help='XML configuration file')
parser.add_argument('-m', '--map', default='spaceport_america',
help='Name of the map in Config/Other/Maps.xml')
parser.add_argument('-m', '--mode', help='Mode of execution', choices=['training', 'classification', 'article'], default='article')
parser.add_argument('-i', '--input_image', help='Image to process', default='./asl_alphabet_test/A_test.jpg')
parser.add_argument('-s', '--training_set', help='Data set', default='./TrainingSet/')
parser.add_argument('-mp', '--model_path', help='Model path', default='./TrainedModel/model.txt')
return parser.parse_args()
13 changes: 13 additions & 0 deletions Projet/Utils/ReadWrite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ReadWrite:
@staticmethod
def read(path):
file = open(path, 'r')
return file.readlines()

@staticmethod
def write(path, data):
file = open(path, 'a+')
file.write(data)
file.close()


Binary file added Projet/Utils/__pycache__/ArgParser.cpython-35.pyc
Binary file not shown.
Binary file added Projet/Utils/__pycache__/ReadWrite.cpython-35.pyc
Binary file not shown.
Binary file added Projet/Utils/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file modified Projet/__pycache__/Bootstrap.cpython-35.pyc
Binary file not shown.

0 comments on commit 3f06144

Please sign in to comment.