fidn.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding:utf-8 -*-
  2. import numpy as np
  3. li = [[467, 360, 564, 453], [472, 362, 478, 368], [472, 383, 510, 450], [485, 414, 504, 436], [464, 451, 471, 460],
  4. [543, 454, 550, 461], [25, 467, 31, 478], [515, 549, 523, 557], [346, 554, 351, 563], [461, 557, 557, 608],
  5. [498, 559, 512, 573], [514, 559, 534, 573], [333, 562, 359, 565], [489, 566, 496, 573], [554, 566, 560, 573],
  6. [75, 591, 86, 599], [550, 591, 555, 604], [25, 626, 32, 635], [523, 707, 529, 715], [476, 715, 566, 780],
  7. [528, 738, 536, 747], [520, 755, 526, 764], [499, 766, 549, 772]]
  8. def neighbor_change(li):
  9. li = np.array(li)
  10. x_max = 0
  11. y_max = 0
  12. for i in li:
  13. if i[2] > x_max:
  14. x_max = i[2]
  15. if i[3] > y_max:
  16. y_max = i[3]
  17. def _find_right(boxes, x_max,i,j):
  18. for xs in range(boxes[i][2], x_max):
  19. for ys in range(boxes[i][1], boxes[i][3]):
  20. if boxes[j][0] < xs < boxes[j][2] and boxes[j][1] < ys < boxes[j][2]:
  21. print('----------------------')
  22. print(boxes[i], boxes[j])
  23. boxes[i][0] = min(boxes[i][0],boxes[j][0])
  24. boxes[i][1] = min(boxes[i][1],boxes[j][1])
  25. boxes[i][2] = max(boxes[i][2],boxes[j][2])
  26. boxes[i][3] = max(boxes[i][3],boxes[j][3])
  27. print(boxes[i], boxes[j])
  28. return 1
  29. def _find_down(boxes, y_max,i,j):
  30. for xs in range(boxes[i][0], boxes[i][2]):
  31. for ys in range(boxes[i][3], y_max):
  32. if boxes[j][0] < xs < boxes[j][2] and boxes[j][1] < ys < boxes[j][2]:
  33. print('----------------------')
  34. print(boxes[i], boxes[j])
  35. boxes[i][0] = min(boxes[i][0],boxes[j][0])
  36. boxes[i][1] = min(boxes[i][1],boxes[j][1])
  37. boxes[i][2] = max(boxes[i][2],boxes[j][2])
  38. boxes[i][3] = max(boxes[i][3],boxes[j][3])
  39. print(boxes[i], boxes[j])
  40. return 1
  41. for i in range(len(li)):
  42. for j in range(i + 1, len(li)):
  43. _find_right(li, x_max,i,j)
  44. _find_down(li, y_max, i, j)
  45. # for xs in range(li[i][2],x_max):
  46. # for ys in range(li[i][1],li[i][3]):
  47. # if li[j][0]<xs<li[j][2] and li[j][1]<ys<li[j][2]:
  48. # print(li[i],li[j])
  49. # break