-
Notifications
You must be signed in to change notification settings - Fork 0
/
TesterqNN.py
108 lines (63 loc) · 2.15 KB
/
TesterqNN.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
106
107
108
from os import listdir
import functions
from math import sqrt
from collections import Counter
koefs = [[1, 2], [1, 3], [1, 4], [2, 2], [3, 2], [4, 2], [6, 2]]
koefs_str = ['(1,2)', '(1,3)', '(1,4)', '(2,2)', '(3,2)', '(4,2)', '(6,2)']
scale = 1.0
q = 7
model = "Dassault Rafale"
input_path = 'E:\Faks\Zavrsni\FullDB\Test Planes\Saab JAS 39 Gripen\Side\side46.jpg'
data_path = "E:\Faks\Zavrsni\FullDB\Data\\"
normalization_path = 'E:\Faks\Zavrsni\FullDB\\normalization_data.txt'
loaded = {}
possible = {}
# Picking up the saved data of all known planes
planes = listdir(data_path)
for plane in planes:
cameras = listdir(data_path + plane)
for camera in cameras:
file = open(data_path + plane + '\\' + camera + '\\' + 'normal.txt', "r")
name = ''
for line in file:
if line[0] == '#':
name = line.strip()
possible[plane + name] = {}
elif line[0] == '*':
spl = line.split('->')
curr_coeff = spl[0][1:]
if curr_coeff in koefs_str:
possible[plane + name][curr_coeff] = float(spl[1])
file.close()
gdf = functions.calc(input_path, koefs, scale)
mean = {}
stdev = {}
with open(normalization_path, 'r') as file:
for line in file:
if line[0] == '$':
spl = line.split('->')
mean[spl[0][1:]] = float(spl[1])
elif line[0] == '&':
spl = line.split('->')
stdev[spl[0][1:]] = float(spl[1])
for line in gdf.splitlines():
if line[0] == '*':
spl = line.split('->')
loaded[spl[0][1:]] = float(spl[1])
# Normalizing calculated values
for l in loaded:
loaded[l] = (loaded[l] - mean[l]) / stdev[l]
distance = {}
for plane in possible:
diff_sum = 0
for coeff in possible[plane]:
diff_sum += (possible[plane][coeff] - loaded[coeff])**2
distance[plane] = sqrt(diff_sum)
sorted_distances = sorted(distance.items(), key=lambda x: x[1])[0:q]
closest = []
for i in sorted_distances:
closest.append(i[0].split('#')[0])
counted = Counter(closest)
result = counted.most_common()[0][0]
print(counted)
print(result)