organize_drawing_according_to_details.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import order_bounding_boxes_in_each_block
  2. import re
  3. def get_details(result):
  4. #print(result)
  5. reg = r"([A-Z]\W?[A-Z]?\s?\W\s?\d\d?\s?\s?:\s?\d\d?\s?\W)"
  6. details_ = []
  7. details = []
  8. for element in result:
  9. blubi = ""
  10. for blub in element:
  11. blubi += blub[4] + " "
  12. if re.match(reg,blubi):
  13. details_.append(element)
  14. for elem in details_:
  15. #print(elem)
  16. ymin = 100000000
  17. ymax = 0
  18. xmin = 100000000
  19. xmax = 0
  20. text = ""
  21. for blub in elem:
  22. text += blub[4]
  23. #print(text)
  24. if float(blub[1]) < ymin:
  25. ymin = float(blub[1])
  26. # print("y_min:",y_min)
  27. if float(blub[0]) < xmin:
  28. xmin = float(blub[0])
  29. if float(blub[3]) > ymax:
  30. ymax = float(blub[3])
  31. if float(blub[2]) > xmax:
  32. xmax = float(blub[2])
  33. details.append(list((xmin, ymin,xmax, ymax,text)))
  34. #print(details)
  35. return details
  36. file = "/home/bscheibel/PycharmProjects/dxf_reader/drawings/5129275_Rev01-GV12.html"
  37. result = order_bounding_boxes_in_each_block.get_bound_box(file)
  38. details = get_details(result)
  39. details.sort(key= lambda x: x[0])
  40. print(details)
  41. sections = []
  42. left_x = details[0][0]
  43. right_x = details[0][2]