-
Notifications
You must be signed in to change notification settings - Fork 1
/
feature_extraction_cli.py
105 lines (88 loc) · 3.18 KB
/
feature_extraction_cli.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
98
99
100
101
102
103
104
105
"""
Measuring Similarity of Hand Images Using Color Moments and Histogram of Oriented Gradients
This is the CLI for the First Phase of the Project
Author : Sumukh Ashwin Kamath
(ASU ID - 1217728013 email - skamath6@asu.edu
"""
import argparse
import os
import sys
import warnings
from utils.inputhelper import get_input_feature_extractor_model, get_input_image, get_input_folder, get_task_number
import numpy
from classes.featureextraction import ExtractFeatures
warnings.filterwarnings("ignore")
def numpy_set_params():
"""Set limits for numpy"""
numpy.set_printoptions(suppress=True)
numpy.set_printoptions(threshold=sys.maxsize)
def get_input_dist():
"""Gets the distance measure to be used for computing similarity"""
try:
dist = int(input("Enter the distance measure to be used for computing similarity: Choices\n"
"1. Weighted Manhattan\n2. Manhattan\n3. Euclidean\n"))
if dist not in [1, 2, 3]:
print("Please enter a valid choice")
return get_input_dist()
elif dist == 1:
dist = "WM"
elif dist == 2:
dist = "MH"
elif dist == 3:
dist = "EUC"
return dist
except ValueError as exp:
print("Please enter a valid choice")
return get_input_dist()
def get_input_data():
"""Get Inputs from User"""
number_of_tasks = 2
choice = get_task_number(number_of_tasks)
if choice == 1:
folder = get_input_folder()
image = get_input_image(folder)
model = get_input_feature_extractor_model()
feature_extractor = ExtractFeatures(folder, model)
result = feature_extractor.execute(image)
# if model == "LBP":
# result = [float(x) for x in result.strip('[]').split(",")]
print(numpy.array(result))
elif choice == 2:
folder = get_input_folder()
model = get_input_feature_extractor_model()
feature_extractor = ExtractFeatures(folder, model)
feature_extractor.execute()
elif choice == 3:
pass
# f older = get_input_folder()
# image = get_input_image(folder)
# model = get_input_model()
# dist = get_input_dist()
# k_count = get_input_k()
# img = io.imread(os.path.join(folder, image))
# print("Searching {} images closest to {}".format(k_count, os.path.join(folder, image)))
# result, max_dist = search_k_nearest(img, model, dist, k_count)
#
# f = plt.figure()
# f.add_subplot(3, 5, 1)
# plt.imshow(img)
# plt.title("Query Image")
#
# count = 2
# for r in result:
# f.add_subplot(3, 5, count)
# plt.imshow(io.imread(os.path.join(folder, r[0])))
# plt.title("{}\nDistance: {}\nSimilarity: {}%".format(r[0], round(r[1], 3),
# round((1 - (r[1]/max_dist)) * 100),2))
# count = count + 1
# plt.show()
def main():
"""Main function for the program"""
parser = argparse.ArgumentParser(description='CLI for executing Phase 1 of the project')
parser.add_argument('--full', type=bool, help='Displays full array')
full = parser.parse_args().full
if full:
numpy_set_params()
get_input_data()
if __name__ == "__main__":
main()