-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtraining_Leaves.py
99 lines (68 loc) · 2.27 KB
/
training_Leaves.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import sys
import os
from Data import *
from Classifiers import *
from Utils import *
from FeatureExtractors import *
import csv
training_tables = 'Data/Training_Tables/'
all_features = 'all'
without_moments_features = 'nm'
feature_extractors = [all_features, without_moments_features]
#Variables
dynamic_input_dir = 'Data/DataTraining/'
#Default Values
default_feature_extractor = without_moments_features
def read_user_input():
feature_extractor = None
if len(sys.argv) == 1:
feature_extractor = default_feature_extractor
else:
feature_extractor = sys.argv[1]
return feature_extractor
def get_test_data(feature_extractor, dynamic_input_dir):
alldir = [x[0] for x in os.walk(dynamic_input_dir)][1:]
id = 1
first = True
with open(training_tables+"output_"+feature_extractor+".csv","w") as f:
wr = csv.writer(f,delimiter=",")
for input_dir in alldir:
print input_dir
test_data = read_all_grayscale_images(input_dir)
#print test_data
images = test_data.get_images_binary()
#print images
binary_images = []
feature_vecs = []
f_e = Feature_Extractors()
feature_names = None
label = input_dir.split("/")[2]
for im in images:
b_im = get_binary_image_contours(im)
binary_images.append(b_im)
if feature_extractor == all_features:
(feature_names, features) = f_e.all_feature_extractor_traning(b_im, id, label)
id = id + 1
if first == True :
wr.writerow(feature_names)
first = False;
wr.writerow(features)
elif feature_extractor == without_moments_features:
(feature_names, features) = f_e.no_moments_feature_extractor_traning(b_im,id, label)
id = id + 1
if first == True :
wr.writerow(feature_names)
first = False;
wr.writerow(features)
return (feature_names, features)
def display_input_prameters(feature_extractor):
os.system('clear')
print '++++++++++++++++++++++++Parameters+++++++++++++++++++++++'
if feature_extractor == no_moments_features:
print 'Extracting Features without momments.'
else:
print 'Extracting Features with moments.'
print '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++'
feature_extractor = read_user_input()
display_input_prameters(feature_extractor)
get_test_data(feature_extractor, dynamic_input_dir)