123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- # -*- coding:utf-8 -*-
- import numpy as np
- li = [[467, 360, 564, 453], [472, 362, 478, 368], [472, 383, 510, 450], [485, 414, 504, 436], [464, 451, 471, 460],
- [543, 454, 550, 461], [25, 467, 31, 478], [515, 549, 523, 557], [346, 554, 351, 563], [461, 557, 557, 608],
- [498, 559, 512, 573], [514, 559, 534, 573], [333, 562, 359, 565], [489, 566, 496, 573], [554, 566, 560, 573],
- [75, 591, 86, 599], [550, 591, 555, 604], [25, 626, 32, 635], [523, 707, 529, 715], [476, 715, 566, 780],
- [528, 738, 536, 747], [520, 755, 526, 764], [499, 766, 549, 772]]
- def neighbor_change(li):
- li = np.array(li)
- x_max = 0
- y_max = 0
- for i in li:
- if i[2] > x_max:
- x_max = i[2]
- if i[3] > y_max:
- y_max = i[3]
- def _find_right(boxes, x_max,i,j):
- for xs in range(boxes[i][2], x_max):
- for ys in range(boxes[i][1], boxes[i][3]):
- if boxes[j][0] < xs < boxes[j][2] and boxes[j][1] < ys < boxes[j][2]:
- print('----------------------')
- print(boxes[i], boxes[j])
- boxes[i][0] = min(boxes[i][0],boxes[j][0])
- boxes[i][1] = min(boxes[i][1],boxes[j][1])
- boxes[i][2] = max(boxes[i][2],boxes[j][2])
- boxes[i][3] = max(boxes[i][3],boxes[j][3])
- print(boxes[i], boxes[j])
- return 1
- def _find_down(boxes, y_max,i,j):
- for xs in range(boxes[i][0], boxes[i][2]):
- for ys in range(boxes[i][3], y_max):
- if boxes[j][0] < xs < boxes[j][2] and boxes[j][1] < ys < boxes[j][2]:
- print('----------------------')
- print(boxes[i], boxes[j])
- boxes[i][0] = min(boxes[i][0],boxes[j][0])
- boxes[i][1] = min(boxes[i][1],boxes[j][1])
- boxes[i][2] = max(boxes[i][2],boxes[j][2])
- boxes[i][3] = max(boxes[i][3],boxes[j][3])
- print(boxes[i], boxes[j])
- return 1
- for i in range(len(li)):
- for j in range(i + 1, len(li)):
- _find_right(li, x_max,i,j)
- _find_down(li, y_max, i, j)
- # for xs in range(li[i][2],x_max):
- # for ys in range(li[i][1],li[i][3]):
- # if li[j][0]<xs<li[j][2] and li[j][1]<ys<li[j][2]:
- # print(li[i],li[j])
- # break
|