質問編集履歴
6
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,7 +40,31 @@
|
|
40
40
|
|
41
41
|
範囲リストの要素数をカウントして表示
|
42
42
|
|
43
|
-
|
43
|
+
・・・・・・・・・・・・・・・・・・・・・・・・・・・・
|
44
|
+
|
45
|
+
la1: 前時刻の粒子数
|
46
|
+
|
47
|
+
l0: 前時刻の粒子数
|
48
|
+
|
49
|
+
la2: 後時刻の粒子数
|
50
|
+
|
51
|
+
kinbou[x y]
|
52
|
+
|
53
|
+
kinbou[x y] ←これを画像枚数-1回出力
|
54
|
+
|
55
|
+
kinbou[x y]
|
56
|
+
|
57
|
+
・ ←各時刻で対応する粒子数と同じ回数
|
58
|
+
|
59
|
+
・
|
60
|
+
|
61
|
+
・
|
62
|
+
|
63
|
+
・
|
64
|
+
|
65
|
+
AA:AA、AB:ABリストの要素数
|
66
|
+
|
67
|
+
・・・・・・・・・・・・・・・・・・・・・・・・・・・・
|
44
68
|
|
45
69
|
```
|
46
70
|
|
@@ -60,11 +84,11 @@
|
|
60
84
|
|
61
85
|
la2: 1260
|
62
86
|
|
63
|
-
[801 136]
|
87
|
+
kinbou[801 136]
|
64
|
-
|
88
|
+
|
65
|
-
[830 296]
|
89
|
+
kinbou[830 296]
|
66
|
-
|
90
|
+
|
67
|
-
[963 193]
|
91
|
+
kinbou[963 193]
|
68
92
|
|
69
93
|
AA:1 AB:0
|
70
94
|
|
@@ -74,13 +98,13 @@
|
|
74
98
|
|
75
99
|
la2: 1276
|
76
100
|
|
77
|
-
[800 143]
|
101
|
+
kinbou[800 143]
|
78
|
-
|
102
|
+
|
79
|
-
[831 296]
|
103
|
+
kinbou[831 296]
|
80
|
-
|
104
|
+
|
81
|
-
[961 185]
|
105
|
+
kinbou[961 185]
|
82
|
-
|
106
|
+
|
83
|
-
[ 823 -181]
|
107
|
+
kinbou[ 823 -181]
|
84
108
|
|
85
109
|
AA:1 AB:0
|
86
110
|
|
@@ -210,7 +234,7 @@
|
|
210
234
|
|
211
235
|
# 近傍点を特定
|
212
236
|
|
213
|
-
for e in range(l
|
237
|
+
for e in range(la1):
|
214
238
|
|
215
239
|
|
216
240
|
|
@@ -266,9 +290,7 @@
|
|
266
290
|
|
267
291
|
knn_model = NearestNeighbors(n_neighbors=k, algorithm='brute').fit(l1e)
|
268
292
|
|
269
|
-
distances, indices = knn_model.kneighbors([l0[e]])
|
293
|
+
distances, indices = knn_model.kneighbors([l0[e]])
|
270
|
-
|
271
|
-
#print("K Nearest Neighbors:")
|
272
294
|
|
273
295
|
|
274
296
|
|
@@ -286,7 +308,7 @@
|
|
286
308
|
|
287
309
|
l1 -= kinbou
|
288
310
|
|
289
|
-
print(kinbou)
|
311
|
+
print("kinbou" + str(kinbou))
|
290
312
|
|
291
313
|
|
292
314
|
|
@@ -332,8 +354,6 @@
|
|
332
354
|
|
333
355
|
break
|
334
356
|
|
335
|
-
|
336
|
-
|
337
357
|
```
|
338
358
|
|
339
359
|
|
5
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -210,7 +210,7 @@
|
|
210
210
|
|
211
211
|
# 近傍点を特定
|
212
212
|
|
213
|
-
for e in range(l
|
213
|
+
for e in range(len(l0)):
|
214
214
|
|
215
215
|
|
216
216
|
|
4
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,19 +60,11 @@
|
|
60
60
|
|
61
61
|
la2: 1260
|
62
62
|
|
63
|
-
l1e: 1153
|
64
|
-
|
65
|
-
|
63
|
+
[801 136]
|
66
|
-
|
67
|
-
|
64
|
+
|
68
|
-
|
69
|
-
|
65
|
+
[830 296]
|
70
|
-
|
66
|
+
|
71
|
-
|
67
|
+
[963 193]
|
72
|
-
|
73
|
-
l0[e]: [806, 137]
|
74
|
-
|
75
|
-
l1e: 0
|
76
68
|
|
77
69
|
AA:1 AB:0
|
78
70
|
|
@@ -82,48 +74,16 @@
|
|
82
74
|
|
83
75
|
la2: 1276
|
84
76
|
|
85
|
-
l1e: 1266
|
86
|
-
|
87
|
-
l0[e]: [435, 27]
|
88
|
-
|
89
|
-
l1e: 600
|
90
|
-
|
91
|
-
l0[e]: [801, 136]
|
92
|
-
|
93
|
-
l1e: 90
|
94
|
-
|
95
|
-
l0[e]: [803, 139]
|
96
|
-
|
97
|
-
l1e: 8
|
98
|
-
|
99
|
-
|
77
|
+
[800 143]
|
100
|
-
|
78
|
+
|
101
|
-
|
79
|
+
[831 296]
|
80
|
+
|
81
|
+
[961 185]
|
82
|
+
|
83
|
+
[ 823 -181]
|
102
84
|
|
103
85
|
AA:1 AB:0
|
104
86
|
|
105
|
-
la1: 1276
|
106
|
-
|
107
|
-
l0: 1276
|
108
|
-
|
109
|
-
la2: 1255
|
110
|
-
|
111
|
-
l1e: 1129
|
112
|
-
|
113
|
-
l0[e]: [803, 139]
|
114
|
-
|
115
|
-
l1e: 353
|
116
|
-
|
117
|
-
l0[e]: [800, 143]
|
118
|
-
|
119
|
-
l1e: 30
|
120
|
-
|
121
|
-
l0[e]: [1212, 203]
|
122
|
-
|
123
|
-
l1e: 0
|
124
|
-
|
125
|
-
AA:2 AB:0
|
126
|
-
|
127
87
|
```
|
128
88
|
|
129
89
|
|
@@ -160,216 +120,218 @@
|
|
160
120
|
|
161
121
|
n = 0
|
162
122
|
|
163
|
-
for n in range(
|
164
|
-
|
165
|
-
img1 = cv2.imread('mask_%04d.jpg' % n,cv2.IMREAD_GRAYSCALE)
|
166
|
-
|
167
|
-
img2 = cv2.imread('mask_%04d.jpg' % (n+1),cv2.IMREAD_GRAYSCALE)
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
# ラベリング処理
|
172
|
-
|
173
|
-
label1 = cv2.connectedComponentsWithStats(img1)
|
174
|
-
|
175
|
-
label2 = cv2.connectedComponentsWithStats(img2)
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
# オブジェクト情報を項目別に抽出
|
180
|
-
|
181
|
-
la1 = label1[0] - 1
|
182
|
-
|
183
|
-
data1 = np.delete(label1[2], 0, 0)
|
184
|
-
|
185
|
-
center1 = np.delete(label1[3], 0, 0)
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
la2 = label2[0] - 1
|
190
|
-
|
191
|
-
data2 = np.delete(label2[2], 0, 0)
|
192
|
-
|
193
|
-
center2 = np.delete(label2[3], 0, 0)
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
print("la1:",la1)
|
198
|
-
|
199
|
-
l0 = []
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
# 前時刻のオブジェクト情報を取得
|
204
|
-
|
205
|
-
for i in range(la1):
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
l0 += [[int(center1[i][0]),int(center1[i][1])]]
|
210
|
-
|
211
|
-
i += 1
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
if i == la1:
|
216
|
-
|
217
|
-
break
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
print("l0:",len(l0))
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
l1 = []
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
# 後時刻のオブジェクト情報を取得
|
230
|
-
|
231
|
-
for j in range(la2):
|
232
|
-
|
233
|
-
l1 += [[int(center2[j][0]),int(center2[j][1])]]
|
234
|
-
|
235
|
-
j += 1
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
if j == la2:
|
240
|
-
|
241
|
-
break
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
e = 0
|
123
|
+
for n in range(2):
|
124
|
+
|
125
|
+
img1 = cv2.imread('mask_%04d.jpg' % n,cv2.IMREAD_GRAYSCALE)
|
126
|
+
|
127
|
+
img2 = cv2.imread('mask_%04d.jpg' % (n+1),cv2.IMREAD_GRAYSCALE)
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
# ラベリング処理
|
132
|
+
|
133
|
+
label1 = cv2.connectedComponentsWithStats(img1)
|
134
|
+
|
135
|
+
label2 = cv2.connectedComponentsWithStats(img2)
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
# オブジェクト情報を項目別に抽出
|
140
|
+
|
141
|
+
la1 = label1[0] - 1
|
142
|
+
|
143
|
+
data1 = np.delete(label1[2], 0, 0)
|
144
|
+
|
145
|
+
center1 = np.delete(label1[3], 0, 0)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
la2 = label2[0] - 1
|
150
|
+
|
151
|
+
data2 = np.delete(label2[2], 0, 0)
|
152
|
+
|
153
|
+
center2 = np.delete(label2[3], 0, 0)
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
print("la1:",la1)
|
158
|
+
|
159
|
+
l0 = []
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
# 前時刻のオブジェクト情報を取得
|
164
|
+
|
165
|
+
for i in range(la1):
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
l0 += [[int(center1[i][0]),int(center1[i][1])]]
|
170
|
+
|
171
|
+
i += 1
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
if i == la1:
|
176
|
+
|
177
|
+
break
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
print("l0:",len(l0))
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
l1 = []
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
# 後時刻のオブジェクト情報を取得
|
190
|
+
|
191
|
+
for j in range(la2):
|
192
|
+
|
193
|
+
l1 += [[int(center2[j][0]),int(center2[j][1])]]
|
194
|
+
|
195
|
+
j += 1
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
if j == la2:
|
200
|
+
|
201
|
+
break
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
e = 0
|
246
206
|
|
247
207
|
|
248
208
|
|
249
|
-
print("la2:",la2)
|
250
|
-
|
251
|
-
# 近傍点を特定
|
252
|
-
|
253
|
-
for e in range(la1):
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
l1e = []
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
# 探査範囲内のオブジェクト情報を取得
|
262
|
-
|
263
|
-
for l in range(la2):
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
if int(l1[l][0]) >= (int(l0[e][0]) - 5):
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
l1e += [[int(l1[l][0]),int(l1[l][1])]]
|
274
|
-
|
275
|
-
l += 1
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
else:
|
280
|
-
|
281
|
-
l += 1
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
if l == la2:
|
209
|
+
print("la2:",la2)
|
210
|
+
|
211
|
+
# 近傍点を特定
|
212
|
+
|
213
|
+
for e in range(la1):
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
l1e = []
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
# 探査範囲内のオブジェクト情報を取得
|
222
|
+
|
223
|
+
for l in range(la2):
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
if int(l1[l][0]) >= (int(l0[e][0]) - 5):
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
l1e += [[int(l1[l][0]),int(l1[l][1])]]
|
234
|
+
|
235
|
+
l += 1
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
else:
|
240
|
+
|
241
|
+
l += 1
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
if l == la2:
|
246
|
+
|
247
|
+
break
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
if len(l1e) == 0:
|
252
|
+
|
253
|
+
break
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
l1e = np.array(l1e)
|
260
|
+
|
261
|
+
#print("l1e:",len(l1e))
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
#モデル構築
|
266
|
+
|
267
|
+
knn_model = NearestNeighbors(n_neighbors=k, algorithm='brute').fit(l1e)
|
268
|
+
|
269
|
+
distances, indices = knn_model.kneighbors([l0[e]])
|
270
|
+
|
271
|
+
#print("K Nearest Neighbors:")
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
#K個までのスライス、現在Kは1個
|
276
|
+
|
277
|
+
for rank, index in enumerate(indices[0][:k], start=1):
|
278
|
+
|
279
|
+
str(rank) + " ==>",l1e[index]
|
280
|
+
|
281
|
+
str(rank) + " ==>", distances[0][0]
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
kinbou = l1e[index]
|
286
|
+
|
287
|
+
l1 -= kinbou
|
288
|
+
|
289
|
+
print(kinbou)
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
if distances[0][0] < 150 and 1920 >= kinbou[0] >= 0 and 2160 >= kinbou[1] >= 0 :
|
296
|
+
|
297
|
+
AA += [kinbou]
|
298
|
+
|
299
|
+
l1e = l1e.tolist()
|
300
|
+
|
301
|
+
del l1e[:]
|
302
|
+
|
303
|
+
e += 1
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
elif distances[0][0] < 150 and 3840 >= kinbou[0] > 1920 and 2160 >= kinbou[1] >= 0 :
|
308
|
+
|
309
|
+
AB += [kinbou]
|
310
|
+
|
311
|
+
l1e = l1e.tolist()
|
312
|
+
|
313
|
+
del l1e[:]
|
314
|
+
|
315
|
+
e += 1
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
print("AA" + ":" + str(len(AA)) + " " + "AB" + ":" + str(len(AB)))
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
if img2 is None:
|
330
|
+
|
331
|
+
print("can't read")
|
286
332
|
|
287
333
|
break
|
288
334
|
|
289
|
-
|
290
|
-
|
291
|
-
l1e = np.array(l1e)
|
292
|
-
|
293
|
-
print("l1e:",len(l1e))
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
if len(l1e) == 0:
|
298
|
-
|
299
|
-
break
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
print("l0[e]:",l0[e])
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
#モデル構築
|
308
|
-
|
309
|
-
knn_model = NearestNeighbors(n_neighbors=k, algorithm='ball_tree').fit(l1e)
|
310
|
-
|
311
|
-
distances, indices = knn_model.kneighbors([l0[e]])
|
312
|
-
|
313
|
-
#print("K Nearest Neighbors:")
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
#K個までのスライス、現在Kは1個
|
318
|
-
|
319
|
-
for rank, index in enumerate(indices[0][:k], start=1):
|
320
|
-
|
321
|
-
str(rank) + " ==>",l1e[index]
|
322
|
-
|
323
|
-
str(rank) + " ==>", distances[0][0]
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
kinbou = l1e[index]
|
328
|
-
|
329
|
-
l1 -= kinbou
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
if distances[0][0] < 150 and 1920 >= kinbou[0] >= 0 and 2160 >= kinbou[1] >= 0 :
|
334
|
-
|
335
|
-
AA += [kinbou]
|
336
|
-
|
337
|
-
#l1e = l1e.tolist()
|
338
|
-
|
339
|
-
#del l1e[:]
|
340
|
-
|
341
|
-
e += 1
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
elif distances[0][0] < 150 and 3840 >= kinbou[0] > 1920 and 2160 >= kinbou[1] >= 0 :
|
346
|
-
|
347
|
-
AB += [kinbou]
|
348
|
-
|
349
|
-
#l1e = l1e.tolist()
|
350
|
-
|
351
|
-
#del l1e[:]
|
352
|
-
|
353
|
-
e += 1
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
print("AA" + ":" + str(len(AA)) + " " + "AB" + ":" + str(len(AB)))
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
if img2 is None:
|
368
|
-
|
369
|
-
print("can't read")
|
370
|
-
|
371
|
-
break
|
372
|
-
|
373
335
|
|
374
336
|
|
375
337
|
```
|
3
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,13 +58,21 @@
|
|
58
58
|
|
59
59
|
l0: 1263
|
60
60
|
|
61
|
-
1153
|
62
|
-
|
63
|
-
|
61
|
+
la2: 1260
|
64
|
-
|
62
|
+
|
65
|
-
5
|
63
|
+
l1e: 1153
|
66
|
-
|
64
|
+
|
67
|
-
[8
|
65
|
+
l0[e]: [800, 136]
|
66
|
+
|
67
|
+
l1e: 557
|
68
|
+
|
69
|
+
l0[e]: [803, 140]
|
70
|
+
|
71
|
+
l1e: 83
|
72
|
+
|
73
|
+
l0[e]: [806, 137]
|
74
|
+
|
75
|
+
l1e: 0
|
68
76
|
|
69
77
|
AA:1 AB:0
|
70
78
|
|
@@ -72,9 +80,25 @@
|
|
72
80
|
|
73
81
|
l0: 1260
|
74
82
|
|
83
|
+
la2: 1276
|
84
|
+
|
75
|
-
1266
|
85
|
+
l1e: 1266
|
86
|
+
|
76
|
-
|
87
|
+
l0[e]: [435, 27]
|
88
|
+
|
89
|
+
l1e: 600
|
90
|
+
|
91
|
+
l0[e]: [801, 136]
|
92
|
+
|
93
|
+
l1e: 90
|
94
|
+
|
95
|
+
l0[e]: [803, 139]
|
96
|
+
|
97
|
+
l1e: 8
|
98
|
+
|
77
|
-
[80
|
99
|
+
l0[e]: [807, 143]
|
100
|
+
|
101
|
+
l1e: 0
|
78
102
|
|
79
103
|
AA:1 AB:0
|
80
104
|
|
@@ -82,11 +106,23 @@
|
|
82
106
|
|
83
107
|
l0: 1276
|
84
108
|
|
109
|
+
la2: 1255
|
110
|
+
|
85
|
-
1129
|
111
|
+
l1e: 1129
|
112
|
+
|
86
|
-
|
113
|
+
l0[e]: [803, 139]
|
114
|
+
|
87
|
-
|
115
|
+
l1e: 353
|
116
|
+
|
88
|
-
|
117
|
+
l0[e]: [800, 143]
|
118
|
+
|
119
|
+
l1e: 30
|
120
|
+
|
121
|
+
l0[e]: [1212, 203]
|
122
|
+
|
123
|
+
l1e: 0
|
124
|
+
|
89
|
-
AA:
|
125
|
+
AA:2 AB:0
|
90
126
|
|
91
127
|
```
|
92
128
|
|
@@ -182,6 +218,10 @@
|
|
182
218
|
|
183
219
|
|
184
220
|
|
221
|
+
print("l0:",len(l0))
|
222
|
+
|
223
|
+
|
224
|
+
|
185
225
|
l1 = []
|
186
226
|
|
187
227
|
|
@@ -202,77 +242,71 @@
|
|
202
242
|
|
203
243
|
|
204
244
|
|
205
|
-
print("l0:",len(l0))
|
206
|
-
|
207
245
|
e = 0
|
208
246
|
|
247
|
+
|
248
|
+
|
249
|
+
print("la2:",la2)
|
250
|
+
|
209
251
|
# 近傍点を特定
|
210
252
|
|
211
|
-
for e in range(l
|
253
|
+
for e in range(la1):
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
254
|
+
|
216
|
-
|
255
|
+
|
256
|
+
|
217
|
-
|
257
|
+
l1e = []
|
218
|
-
|
219
|
-
|
220
|
-
|
258
|
+
|
259
|
+
|
260
|
+
|
221
|
-
|
261
|
+
# 探査範囲内のオブジェクト情報を取得
|
222
|
-
|
262
|
+
|
223
|
-
|
263
|
+
for l in range(la2):
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
229
|
-
|
269
|
+
if int(l1[l][0]) >= (int(l0[e][0]) - 5):
|
230
|
-
|
231
|
-
|
232
|
-
|
270
|
+
|
271
|
+
|
272
|
+
|
233
|
-
|
273
|
+
l1e += [[int(l1[l][0]),int(l1[l][1])]]
|
234
|
-
|
274
|
+
|
235
|
-
|
275
|
+
l += 1
|
236
|
-
|
237
|
-
|
238
|
-
|
276
|
+
|
277
|
+
|
278
|
+
|
239
|
-
|
279
|
+
else:
|
240
|
-
|
280
|
+
|
241
|
-
|
281
|
+
l += 1
|
242
|
-
|
243
|
-
|
244
|
-
|
282
|
+
|
283
|
+
|
284
|
+
|
245
|
-
|
285
|
+
if l == la2:
|
246
|
-
|
286
|
+
|
247
|
-
|
287
|
+
break
|
248
|
-
|
249
|
-
|
288
|
+
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
289
|
+
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
l1e = oo()
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
290
|
|
263
291
|
l1e = np.array(l1e)
|
264
292
|
|
265
|
-
print(len(l1e))
|
293
|
+
print("l1e:",len(l1e))
|
294
|
+
|
295
|
+
|
266
296
|
|
267
297
|
if len(l1e) == 0:
|
268
298
|
|
269
299
|
break
|
270
300
|
|
301
|
+
|
302
|
+
|
303
|
+
print("l0[e]:",l0[e])
|
304
|
+
|
271
305
|
|
272
306
|
|
273
307
|
#モデル構築
|
274
308
|
|
275
|
-
knn_model = NearestNeighbors(n_neighbors=k, algorithm='br
|
309
|
+
knn_model = NearestNeighbors(n_neighbors=k, algorithm='ball_tree').fit(l1e)
|
276
310
|
|
277
311
|
distances, indices = knn_model.kneighbors([l0[e]])
|
278
312
|
|
@@ -294,16 +328,14 @@
|
|
294
328
|
|
295
329
|
l1 -= kinbou
|
296
330
|
|
297
|
-
print(kinbou)
|
298
|
-
|
299
|
-
|
300
|
-
|
301
331
|
|
302
332
|
|
303
333
|
if distances[0][0] < 150 and 1920 >= kinbou[0] >= 0 and 2160 >= kinbou[1] >= 0 :
|
304
334
|
|
305
335
|
AA += [kinbou]
|
306
336
|
|
337
|
+
#l1e = l1e.tolist()
|
338
|
+
|
307
339
|
#del l1e[:]
|
308
340
|
|
309
341
|
e += 1
|
@@ -314,21 +346,17 @@
|
|
314
346
|
|
315
347
|
AB += [kinbou]
|
316
348
|
|
349
|
+
#l1e = l1e.tolist()
|
350
|
+
|
317
351
|
#del l1e[:]
|
318
352
|
|
319
353
|
e += 1
|
320
354
|
|
321
355
|
|
322
356
|
|
323
|
-
|
357
|
+
|
324
|
-
|
325
|
-
|
358
|
+
|
326
|
-
|
327
|
-
|
359
|
+
|
328
|
-
|
329
|
-
break
|
330
|
-
|
331
|
-
|
332
360
|
|
333
361
|
|
334
362
|
|
2
問題の詳細
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,6 +54,10 @@
|
|
54
54
|
|
55
55
|
出力
|
56
56
|
|
57
|
+
la1: 1263
|
58
|
+
|
59
|
+
l0: 1263
|
60
|
+
|
57
61
|
1153
|
58
62
|
|
59
63
|
[801 136]
|
@@ -64,12 +68,20 @@
|
|
64
68
|
|
65
69
|
AA:1 AB:0
|
66
70
|
|
71
|
+
la1: 1260
|
72
|
+
|
73
|
+
l0: 1260
|
74
|
+
|
67
75
|
1266
|
68
76
|
|
69
77
|
[800 143]
|
70
78
|
|
71
79
|
AA:1 AB:0
|
72
80
|
|
81
|
+
la1: 1276
|
82
|
+
|
83
|
+
l0: 1276
|
84
|
+
|
73
85
|
1129
|
74
86
|
|
75
87
|
[995 323]
|
@@ -146,6 +158,8 @@
|
|
146
158
|
|
147
159
|
|
148
160
|
|
161
|
+
print("la1:",la1)
|
162
|
+
|
149
163
|
l0 = []
|
150
164
|
|
151
165
|
|
@@ -160,160 +174,164 @@
|
|
160
174
|
|
161
175
|
i += 1
|
162
176
|
|
177
|
+
|
178
|
+
|
179
|
+
if i == la1:
|
180
|
+
|
181
|
+
break
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
l1 = []
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
# 後時刻のオブジェクト情報を取得
|
190
|
+
|
191
|
+
for j in range(la2):
|
192
|
+
|
193
|
+
l1 += [[int(center2[j][0]),int(center2[j][1])]]
|
194
|
+
|
195
|
+
j += 1
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
if j == la2:
|
200
|
+
|
201
|
+
break
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
print("l0:",len(l0))
|
206
|
+
|
207
|
+
e = 0
|
208
|
+
|
209
|
+
# 近傍点を特定
|
210
|
+
|
211
|
+
for e in range(len(l0)):
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
def oo():
|
216
|
+
|
217
|
+
l1e = []
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
# 探査範囲内のオブジェクト情報を取得
|
222
|
+
|
223
|
+
for l in range(la2):
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
if int(l1[l][0]) >= (int(l0[e][0]) - 5):
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
l1e += [[int(l1[l][0]),int(l1[l][1])]]
|
234
|
+
|
235
|
+
l += 1
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
else:
|
240
|
+
|
241
|
+
l += 1
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
if l == la2:
|
246
|
+
|
247
|
+
break
|
248
|
+
|
249
|
+
return l1e
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
if __name__ == "__main__":
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
l1e = oo()
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
l1e = np.array(l1e)
|
264
|
+
|
265
|
+
print(len(l1e))
|
266
|
+
|
267
|
+
if len(l1e) == 0:
|
268
|
+
|
269
|
+
break
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
#モデル構築
|
274
|
+
|
275
|
+
knn_model = NearestNeighbors(n_neighbors=k, algorithm='brute').fit(l1e)
|
276
|
+
|
277
|
+
distances, indices = knn_model.kneighbors([l0[e]])
|
278
|
+
|
279
|
+
#print("K Nearest Neighbors:")
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
#K個までのスライス、現在Kは1個
|
284
|
+
|
285
|
+
for rank, index in enumerate(indices[0][:k], start=1):
|
286
|
+
|
287
|
+
str(rank) + " ==>",l1e[index]
|
288
|
+
|
289
|
+
str(rank) + " ==>", distances[0][0]
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
kinbou = l1e[index]
|
294
|
+
|
295
|
+
l1 -= kinbou
|
296
|
+
|
297
|
+
print(kinbou)
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
if distances[0][0] < 150 and 1920 >= kinbou[0] >= 0 and 2160 >= kinbou[1] >= 0 :
|
304
|
+
|
305
|
+
AA += [kinbou]
|
306
|
+
|
307
|
+
#del l1e[:]
|
308
|
+
|
309
|
+
e += 1
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
elif distances[0][0] < 150 and 3840 >= kinbou[0] > 1920 and 2160 >= kinbou[1] >= 0 :
|
314
|
+
|
315
|
+
AB += [kinbou]
|
316
|
+
|
317
|
+
#del l1e[:]
|
318
|
+
|
319
|
+
e += 1
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
else:
|
324
|
+
|
325
|
+
#del l1e[:]
|
326
|
+
|
327
|
+
e += 1
|
328
|
+
|
329
|
+
break
|
330
|
+
|
331
|
+
|
332
|
+
|
163
333
|
|
164
334
|
|
165
|
-
if i == la1:
|
166
|
-
|
167
|
-
break
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
l1 = []
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
# 後時刻のオブジェクト情報を取得
|
176
|
-
|
177
|
-
for j in range(la2):
|
178
|
-
|
179
|
-
l1 += [[int(center2[j][0]),int(center2[j][1])]]
|
180
|
-
|
181
|
-
j += 1
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
if j == la2:
|
186
|
-
|
187
|
-
break
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
e = 0
|
192
|
-
|
193
|
-
# 近傍点を特定
|
194
|
-
|
195
|
-
for e in range(len(l0)):
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
def oo():
|
200
|
-
|
201
|
-
l1e = []
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
# 探査範囲内のオブジェクト情報を取得
|
206
|
-
|
207
|
-
for l in range(la2):
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
if int(l1[l][0]) >= (int(l0[e][0]) - 5):
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
l1e += [[int(l1[l][0]),int(l1[l][1])]]
|
218
|
-
|
219
|
-
l += 1
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
else:
|
224
|
-
|
225
|
-
l += 1
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
if l == la2:
|
230
|
-
|
231
|
-
break
|
232
|
-
|
233
|
-
return l1e
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
if __name__ == "__main__":
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
l1e = oo()
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
l1e = np.array(l1e)
|
248
|
-
|
249
|
-
print(len(l1e))
|
250
|
-
|
251
|
-
if len(l1e) == 0:
|
252
|
-
|
253
|
-
break
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
#モデル構築
|
258
|
-
|
259
|
-
knn_model = NearestNeighbors(n_neighbors=k, algorithm='brute').fit(l1e)
|
260
|
-
|
261
|
-
distances, indices = knn_model.kneighbors([l0[e]])
|
262
|
-
|
263
|
-
#print("K Nearest Neighbors:")
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
#K個までのスライス、現在Kは1個
|
268
|
-
|
269
|
-
for rank, index in enumerate(indices[0][:k], start=1):
|
270
|
-
|
271
|
-
str(rank) + " ==>",l1e[index]
|
272
|
-
|
273
|
-
str(rank) + " ==>", distances[0][0]
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
kinbou = l1e[index]
|
278
|
-
|
279
|
-
l1 -= kinbou
|
280
|
-
|
281
|
-
print(kinbou)
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
if distances[0][0] < 150 and 1920 >= kinbou[0] >= 0 and 2160 >= kinbou[1] >= 0 :
|
288
|
-
|
289
|
-
AA += [kinbou]
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
e += 1
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
elif distances[0][0] < 150 and 3840 >= kinbou[0] > 1920 and 2160 >= kinbou[1] >= 0 :
|
298
|
-
|
299
|
-
AB += [kinbou]
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
e += 1
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
else:
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
e += 1
|
312
|
-
|
313
|
-
break
|
314
|
-
|
315
|
-
|
316
|
-
|
317
335
|
print("AA" + ":" + str(len(AA)) + " " + "AB" + ":" + str(len(AB)))
|
318
336
|
|
319
337
|
|
@@ -324,8 +342,6 @@
|
|
324
342
|
|
325
343
|
break
|
326
344
|
|
327
|
-
|
328
|
-
|
329
345
|
|
330
346
|
|
331
347
|
```
|
1
問題の詳細
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,9 +46,37 @@
|
|
46
46
|
|
47
47
|
### 発生している問題・エラーメッセージ
|
48
48
|
|
49
|
-
このうち
|
49
|
+
このうちfor e in range(len(l0)):より下で近傍点の座標をl0の要素の数だけ特定>範囲のリストに入れていくというループ処理をしたいのですが、リストAA、ABにはそれぞれの画像ごとに格納した座標の個数が一つしか(1回しか)格納されていない?ようです。これはやはりループ処理の組み方がおかしいのでしょうか
|
50
|
+
|
51
|
+
|
52
|
+
|
50
|
-
|
53
|
+
```ここに言語を入力
|
54
|
+
|
51
|
-
|
55
|
+
出力
|
56
|
+
|
57
|
+
1153
|
58
|
+
|
59
|
+
[801 136]
|
60
|
+
|
61
|
+
557
|
62
|
+
|
63
|
+
[830 296]
|
64
|
+
|
65
|
+
AA:1 AB:0
|
66
|
+
|
67
|
+
1266
|
68
|
+
|
69
|
+
[800 143]
|
70
|
+
|
71
|
+
AA:1 AB:0
|
72
|
+
|
73
|
+
1129
|
74
|
+
|
75
|
+
[995 323]
|
76
|
+
|
77
|
+
AA:1 AB:0
|
78
|
+
|
79
|
+
```
|
52
80
|
|
53
81
|
|
54
82
|
|
@@ -260,7 +288,7 @@
|
|
260
288
|
|
261
289
|
AA += [kinbou]
|
262
290
|
|
263
|
-
|
291
|
+
|
264
292
|
|
265
293
|
e += 1
|
266
294
|
|
@@ -270,7 +298,7 @@
|
|
270
298
|
|
271
299
|
AB += [kinbou]
|
272
300
|
|
273
|
-
|
301
|
+
|
274
302
|
|
275
303
|
e += 1
|
276
304
|
|
@@ -278,7 +306,7 @@
|
|
278
306
|
|
279
307
|
else:
|
280
308
|
|
281
|
-
|
309
|
+
|
282
310
|
|
283
311
|
e += 1
|
284
312
|
|