-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
169 lines (127 loc) · 5.51 KB
/
run.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"""This is where we will call the functions from the powerful pluzzling algo"""
#%%
from src.border_extraction.get_border import get_image_and_border
from src.border_matching import Matcher
from src.utils import border_ops, display
import matplotlib.pyplot as plt
import numpy as np
import cv2 as cv
from time import time
#%%
start_1 = time()
img, borders = get_image_and_border('dataset\\starry_night\\4_fc.JPG')
print("Time to get image and borders: ", time() - start_1)
#%%
start = time()
img_matcher = Matcher(img, borders=borders, kmeans=False)
print("Time to perform border unrolling and lock identification: ", time() - start)
#%% getting matches
start = time()
weighting = [2,1] # [2,1] is the best weighting for this image
matches = img_matcher.get_matches(weighting=weighting)
print("Time to filter and get matches: ", time() - start)
print("total time: ", time() - start_1)
# # %% displaying top 5 matches on the original image:
# # displaying the original image
if weighting != [2,1]:
plt.imshow(img)
n_display = 5
# displaying the border contours
for match_val, (i,j), match_segs in matches[:n_display]:
display.display_border(borders[i], color='b')
display.display_border(borders[j], color='b')
for match_val, (i,j), match_segs in matches[:n_display]:
# displaying the segment of the border contours:
display.display_border(match_segs[0], c='y')
display.display_border(match_segs[1], c='y')
# drawing a line between the two points:
p1 = match_segs[0][0]
p2 = match_segs[1][0]
plt.plot([p1[0], p2[0]], [p1[1], p2[1]], c='r')
# getting midpoint between p1 and p2:
p3 = [(p1[0]+p2[0])/2, (p1[1]+p2[1])/2]
# adding a label to the line:
plt.text(p3[0], p3[1], str(round(match_val,3)), color='darkgreen')
plt.show()
##################################
# %% coloring in the matches by if they are correct or not:
# for 2-1 weighting:
if weighting == [2,1]:
plt.imshow(img)
n_display = 5
c = ['r','g','b','y','c','m','k']
count = 0
for match_val, (i,j), match_segs in matches[:n_display]:
if count == 0: # Overlaping segment
display.display_border(match_segs[1], s=2.5, c=c[count])
display.display_border(match_segs[0], s=2.5, c=c[count])
elif count == 1:
l = len(match_segs[0])//10
for x in range(0,10,2):
display.display_border(match_segs[0][x*l:(x+1)*l], s=2.5, c=c[count])
display.display_border(match_segs[1], s=2.5, c=c[count])
else:
# Displaying the segment of the border contours:
display.display_border(match_segs[0], s=2.5, c=c[count])
display.display_border(match_segs[1], s=2.5, c=c[count])
# drawing a line between the two points:
p1 = match_segs[0][0]
p2 = match_segs[1][0]
line_clr = 'darkgreen' if count in [1, 2, 4] else 'r'
plt.plot([p1[0], p2[0]], [p1[1], p2[1]], c=line_clr)
# getting midpoint between p1 and p2:
p3 = [(p1[0]+p2[0])/2, (p1[1]+p2[1])/2]
# adding a label to the line:
plt.text(p3[0], p3[1], str(round(match_val,3)), color=line_clr, bbox=dict(facecolor='white', alpha=0.5))
count+=1
plt.show()
# for 0-1 weighting:
# c = ['r','g','b','y','c','m','k']
# count = 0
# for match_val, (i,j), match_segs in matches[:n_display]:
# if count in [2,]:
# s = 0
# l = len(match_segs[s])//10
# for x in range(0,10,2):
# display.display_border(match_segs[s][x*l:(x+1)*l], s=2.5, c=c[count])
# display.display_border(match_segs[not s], s=2.5, c=c[count])
# else:
# # Displaying the segment of the border contours:
# display.display_border(match_segs[0], s=2.5, c=c[count])
# display.display_border(match_segs[1], s=2.5, c=c[count])
# # drawing a line between the two points:
# p1 = match_segs[0][0]
# p2 = match_segs[1][0]
# line_clr = 'darkgreen' if count in [] else 'r'
# plt.plot([p1[0], p2[0]], [p1[1], p2[1]], c=line_clr)
# # getting midpoint between p1 and p2:
# p3 = [(p1[0]+p2[0])/2, (p1[1]+p2[1])/2]
# # adding a label to the line:
# plt.text(p3[0], p3[1], str(round(match_val,3)), color=line_clr, bbox=dict(facecolor='white', alpha=0.5))
# count+=1
# plt.show()
# for 1-0 weighting:
# c = ['r','g','b','y','c','m','k']
# count = 0
# for match_val, (i,j), match_segs in matches[:n_display]:
# if count in [2,4]:
# l = len(match_segs[0])//10
# for x in range(0,10,2):
# display.display_border(match_segs[1][x*l:(x+1)*l], s=2.5, c=c[count])
# display.display_border(match_segs[0], s=2.5, c=c[count])
# else:
# # Displaying the segment of the border contours:
# display.display_border(match_segs[0], s=2.5, c=c[count])
# display.display_border(match_segs[1], s=2.5, c=c[count])
# # drawing a line between the two points:
# p1 = match_segs[0][0]
# p2 = match_segs[1][0]
# line_clr = 'darkgreen' if count in [0] else 'r'
# plt.plot([p1[0], p2[0]], [p1[1], p2[1]], c=line_clr)
# # getting midpoint between p1 and p2:
# p3 = [(p1[0]+p2[0])/2, (p1[1]+p2[1])/2]
# # adding a label to the line:
# plt.text(p3[0], p3[1], str(round(match_val,3)), color=line_clr, bbox=dict(facecolor='white', alpha=0.5))
# count+=1
# plt.show()
# %%