Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41707ab

Browse files
committed
156对 #有问题
1 parent 47af89b commit 41707ab

File tree

1 file changed

+181
-8
lines changed

1 file changed

+181
-8
lines changed

my08-opencv玩游戏game/连连看/compare_photos.py

+181-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""
1010

1111
import cv2, pickle
12+
from pprint import pprint
1213

1314
with open('photo_mat', 'rb') as f:
1415
mat = pickle.load(f)
@@ -36,7 +37,7 @@ def compare(i, j, img):
3637
if x < i:
3738
continue
3839
for y in range(lenY):
39-
if y < j:
40+
if x <= i and y < j:
4041
continue
4142
z = mat[x][y]
4243
# 图片相似度
@@ -49,7 +50,9 @@ def compare(i, j, img):
4950
# if abs(image_difference-1)>0.5:
5051
# if image_difference < 0.1:
5152
# pairs.append((i, j, x, y, image_difference))
52-
if res[0][0] >= 0.9 and (i != x and j != y):
53+
if res[0][0] >= 0.8 :#and (i != x and j != y):
54+
if i ==x and j ==y:
55+
continue
5356
pairs.append((i, j, x, y, res[0][0]))
5457
print('--------')
5558

@@ -58,12 +61,168 @@ def compare(i, j, img):
5861
for j, y in enumerate(x):
5962
compare(i, j, y)
6063

61-
print('--------')
62-
print(pairs)#33对?
63-
#[(0, 0, 5, 3, 0.93773538), (0, 3, 2, 6, 0.94418496), (0, 3, 3, 4, 0.97784418), (0, 3, 5, 6, 0.91531861), (0, 3, 7, 4, 0.90034771), (0, 4, 1, 5, 0.9859665), (0, 4, 2, 5, 0.97593749), (0, 4, 5, 7, 0.92510819), (1, 0, 2, 4, 0.95577663), (1, 0, 2, 5, 0.93438679), (1, 0, 3, 2, 0.98244762), (1, 0, 5, 1, 0.95950162), (1, 0, 5, 7, 0.9012484), (1, 0, 7, 3, 0.91213149), (1, 2, 4, 3, 0.97030866), (1, 3, 7, 5, 0.90350145), (1, 4, 3, 5, 0.92840946), (1, 4, 3, 6, 0.92976296), (1, 5, 5, 7, 0.93449652), (2, 1, 6, 4, 0.91386253), (2, 4, 5, 7, 0.95080549), (2, 5, 5, 7, 0.95228308), (3, 2, 5, 7, 0.94026983), (3, 2, 7, 3, 0.95594138), (3, 4, 5, 6, 0.96190572), (3, 4, 8, 7, 0.90763825), (4, 1, 7, 2, 0.95110172), (4, 3, 6, 6, 0.95759535), (5, 1, 7, 3, 0.97735828), (5, 2, 8, 3, 0.96606308), (5, 6, 8, 7, 0.92764288), (6, 0, 7, 3, 0.96886152), (7, 4, 8, 7, 0.93397516)]
64-
65-
66-
64+
print('--------',len(pairs))
65+
pprint(pairs)#156对 #有问题
66+
'''
67+
[(0, 0, 0, 4, 0.81783479),
68+
(0, 0, 1, 0, 0.82939386),
69+
(0, 0, 1, 5, 0.80112994),
70+
(0, 0, 2, 4, 0.81963593),
71+
(0, 0, 2, 5, 0.80141765),
72+
(0, 0, 3, 2, 0.83176291),
73+
(0, 0, 5, 1, 0.82441366),
74+
(0, 0, 5, 3, 0.93773538),
75+
(0, 0, 6, 0, 0.80839384),
76+
(0, 0, 7, 3, 0.80357623),
77+
(0, 1, 4, 6, 0.84010893),
78+
(0, 2, 4, 5, 0.89919138),
79+
(0, 2, 5, 5, 0.89656675),
80+
(0, 2, 6, 2, 0.87691551),
81+
(0, 3, 2, 6, 0.94418496),
82+
(0, 3, 3, 4, 0.97784418),
83+
(0, 3, 5, 6, 0.91531861),
84+
(0, 3, 7, 4, 0.90034771),
85+
(0, 3, 8, 7, 0.8669098),
86+
(0, 4, 1, 0, 0.95897603),
87+
(0, 4, 1, 5, 0.9859665),
88+
(0, 4, 2, 3, 0.84755546),
89+
(0, 4, 2, 4, 0.98988521),
90+
(0, 4, 2, 5, 0.97593749),
91+
(0, 4, 3, 2, 0.96898985),
92+
(0, 4, 5, 1, 0.93505126),
93+
(0, 4, 5, 7, 0.92510819),
94+
(0, 4, 6, 0, 0.88995898),
95+
(0, 4, 7, 3, 0.91428041),
96+
(0, 5, 2, 0, 0.90362453),
97+
(0, 5, 2, 1, 0.93313634),
98+
(0, 5, 6, 4, 0.88912612),
99+
(0, 7, 2, 7, 0.98162633),
100+
(0, 7, 3, 0, 0.84628779),
101+
(0, 7, 6, 7, 0.85053468),
102+
(1, 0, 1, 5, 0.93375051),
103+
(1, 0, 2, 3, 0.80927575),
104+
(1, 0, 2, 4, 0.95577663),
105+
(1, 0, 2, 5, 0.93438679),
106+
(1, 0, 3, 2, 0.98244762),
107+
(1, 0, 5, 1, 0.95950162),
108+
(1, 0, 5, 7, 0.9012484),
109+
(1, 0, 6, 0, 0.93606734),
110+
(1, 0, 7, 0, 0.81604606),
111+
(1, 0, 7, 3, 0.91213149),
112+
(1, 1, 7, 1, 0.8624481),
113+
(1, 2, 1, 7, 0.94927907),
114+
(1, 2, 4, 3, 0.97030866),
115+
(1, 2, 6, 6, 0.89334244),
116+
(1, 3, 7, 5, 0.90350145),
117+
(1, 4, 3, 5, 0.92840946),
118+
(1, 4, 3, 6, 0.92976296),
119+
(1, 4, 8, 1, 0.87637573),
120+
(1, 4, 8, 5, 0.86086744),
121+
(1, 5, 2, 3, 0.83290088),
122+
(1, 5, 2, 4, 0.98093969),
123+
(1, 5, 2, 5, 0.9865284),
124+
(1, 5, 3, 2, 0.95161527),
125+
(1, 5, 5, 1, 0.91846502),
126+
(1, 5, 5, 7, 0.93449652),
127+
(1, 5, 6, 0, 0.87814039),
128+
(1, 5, 7, 3, 0.91769367),
129+
(1, 6, 3, 3, 0.87408149),
130+
(1, 6, 4, 7, 0.83912045),
131+
(1, 7, 4, 3, 0.93324989),
132+
(1, 7, 6, 6, 0.90282589),
133+
(2, 0, 2, 1, 0.98332465),
134+
(2, 0, 6, 4, 0.89946473),
135+
(2, 1, 6, 4, 0.91386253),
136+
(2, 2, 4, 0, 0.97106832),
137+
(2, 3, 2, 4, 0.85241109),
138+
(2, 3, 2, 5, 0.84527677),
139+
(2, 3, 3, 2, 0.83583575),
140+
(2, 3, 3, 4, 0.80124199),
141+
(2, 3, 5, 1, 0.81944293),
142+
(2, 3, 5, 7, 0.819251),
143+
(2, 3, 7, 0, 0.91440505),
144+
(2, 3, 7, 3, 0.80969107),
145+
(2, 4, 2, 5, 0.9853642),
146+
(2, 4, 3, 2, 0.98278183),
147+
(2, 4, 5, 1, 0.96176714),
148+
(2, 4, 5, 3, 0.81060904),
149+
(2, 4, 5, 7, 0.95080549),
150+
(2, 4, 6, 0, 0.92093289),
151+
(2, 4, 7, 0, 0.82010585),
152+
(2, 4, 7, 3, 0.94900286),
153+
(2, 5, 3, 2, 0.96413034),
154+
(2, 5, 5, 1, 0.93163985),
155+
(2, 5, 5, 3, 0.80133277),
156+
(2, 5, 5, 7, 0.95228308),
157+
(2, 5, 6, 0, 0.89228898),
158+
(2, 5, 7, 0, 0.80005699),
159+
(2, 5, 7, 3, 0.93504852),
160+
(2, 6, 3, 4, 0.9634583),
161+
(2, 6, 5, 6, 0.97281444),
162+
(2, 6, 7, 4, 0.90955776),
163+
(2, 6, 8, 6, 0.81169814),
164+
(2, 6, 8, 7, 0.87542808),
165+
(2, 7, 3, 0, 0.86373925),
166+
(2, 7, 6, 7, 0.90865624),
167+
(3, 0, 6, 7, 0.80371922),
168+
(3, 1, 3, 7, 0.89857602),
169+
(3, 2, 5, 1, 0.98385006),
170+
(3, 2, 5, 3, 0.80837327),
171+
(3, 2, 5, 7, 0.94026983),
172+
(3, 2, 6, 0, 0.95155406),
173+
(3, 2, 7, 0, 0.83519346),
174+
(3, 2, 7, 3, 0.95594138),
175+
(3, 3, 4, 7, 0.81548607),
176+
(3, 3, 8, 4, 0.88165134),
177+
(3, 4, 5, 6, 0.96190572),
178+
(3, 4, 7, 4, 0.95597637),
179+
(3, 4, 8, 7, 0.90763825),
180+
(3, 5, 3, 6, 0.96791953),
181+
(3, 5, 7, 7, 0.81160647),
182+
(3, 5, 8, 5, 0.88941646),
183+
(3, 6, 7, 7, 0.8219896),
184+
(3, 6, 8, 1, 0.80933893),
185+
(3, 6, 8, 5, 0.92017508),
186+
(4, 1, 6, 5, 0.8459152),
187+
(4, 1, 7, 2, 0.95110172),
188+
(4, 2, 6, 1, 0.95789027),
189+
(4, 3, 6, 6, 0.95759535),
190+
(4, 4, 5, 1, 0.80212337),
191+
(4, 4, 7, 3, 0.80778289),
192+
(4, 4, 8, 2, 0.92399627),
193+
(4, 5, 5, 5, 0.98698038),
194+
(4, 5, 6, 2, 0.91531587),
195+
(5, 0, 5, 4, 0.95705253),
196+
(5, 1, 5, 3, 0.81610906),
197+
(5, 1, 5, 7, 0.93452507),
198+
(5, 1, 6, 0, 0.98169124),
199+
(5, 1, 7, 0, 0.84997863),
200+
(5, 1, 7, 3, 0.97735828),
201+
(5, 2, 8, 3, 0.96606308),
202+
(5, 3, 5, 7, 0.80398655),
203+
(5, 3, 6, 0, 0.80013829),
204+
(5, 3, 7, 3, 0.82962543),
205+
(5, 5, 6, 2, 0.91919237),
206+
(5, 6, 7, 4, 0.96237701),
207+
(5, 6, 7, 6, 0.80884886),
208+
(5, 6, 8, 6, 0.80175209),
209+
(5, 6, 8, 7, 0.92764288),
210+
(5, 7, 6, 0, 0.90893477),
211+
(5, 7, 7, 0, 0.82358778),
212+
(5, 7, 7, 3, 0.94626212),
213+
(6, 0, 7, 0, 0.85159588),
214+
(6, 0, 7, 3, 0.96886152),
215+
(6, 3, 8, 0, 0.94173014),
216+
(6, 5, 7, 2, 0.90841216),
217+
(7, 0, 7, 3, 0.84417427),
218+
(7, 4, 8, 7, 0.93397516),
219+
(7, 6, 8, 6, 0.96749038),
220+
(7, 7, 8, 1, 0.80834168),
221+
(7, 7, 8, 5, 0.84336907),
222+
(8, 1, 8, 5, 0.89013624)]
223+
'''
224+
225+
'''
67226
#Test
68227
# 1, 0, 1, 5
69228
a = mat[1][0]
@@ -73,3 +232,17 @@ def compare(i, j, img):
73232
# image_difference = get_image_difference(y1, z1)
74233
res = cv2.matchTemplate(z1, y1, cv2.TM_CCOEFF_NORMED)
75234
print(1, 0, 1, 5, res)
235+
'''
236+
237+
238+
def compare_2(x1, y1, x2, y2):
239+
a = mat[x1][y1]
240+
b = mat[x2][y2]
241+
c1 = cv2.cvtColor(a, cv2.COLOR_BGR2GRAY)
242+
c2 = cv2.cvtColor(b, cv2.COLOR_BGR2GRAY)
243+
# image_difference = get_image_difference(y1, z1)
244+
res = cv2.matchTemplate(c2, c1, cv2.TM_CCOEFF_NORMED)
245+
print(x1, y1, x2, y2, res)
246+
247+
248+
# compare_2(2, 0, 2, 1)

0 commit comments

Comments
 (0)