nominal.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Nominal resolution
  2. for i in range(1, 7):
  3. f = open(f"images/figure{i}.txt", "r")
  4. size_obj = float(f.readline())
  5. f.readline()
  6. max_len = 0
  7. for line in f:
  8. photo_len = list(map(int, line.split()))
  9. number_one = photo_len.count(1)
  10. if (max_len < number_one):
  11. max_len = number_one
  12. f.close()
  13. if max_len == 0:
  14. result = 0
  15. else:
  16. result = float(size_obj / max_len)
  17. print(f"Nominal resolution for figure{i}: {result} mm")
  18. # Determine the offset for two images
  19. x1, y1 = 0, 0
  20. for k in range(1, 3):
  21. with open(f"images/img{k}.txt") as f:
  22. img = f.readlines()
  23. img.pop(0)
  24. img.pop(0)
  25. img = [list(map(int, i.split())) for i in img]
  26. y, x = 0, 0
  27. for i in img:
  28. if 1 in i:
  29. y = img.index(i)
  30. x = i.index(1)
  31. break
  32. if (x1 != 0 and y1 != 0):
  33. x1 = x - x1
  34. y1 = y - y1
  35. else:
  36. x1, y1 = x, y
  37. print(f"\nOffset by y = {y1}, x = {x1}")
  38. print("end of the program")