Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

visualize_frame.py 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (c) 2022 - 2023 Thomas Buck (thomas@xythobuz.de)
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # See <http://www.gnu.org/licenses/>.
  16. import matplotlib.pyplot as plt
  17. import numpy as np
  18. import sys
  19. import math
  20. import os
  21. if len(sys.argv) < 2:
  22. print("Usage:")
  23. print(" " + sys.argv[0] + " filename [...]")
  24. sys.exit(0)
  25. fig, axes = plt.subplots(1, len(sys.argv) - 1, figsize=(15, 5))
  26. # support one or multiple files
  27. if not isinstance(axes, np.ndarray):
  28. axes = [axes]
  29. for n in range(0, len(sys.argv) - 1):
  30. print("reading " + sys.argv[n + 1])
  31. frame = []
  32. if os.path.getsize(sys.argv[n + 1]) == 1296:
  33. print("binary file format detected. parsing.")
  34. with open(sys.argv[n + 1], "rb") as f:
  35. while (byte := f.read(1)):
  36. frame.append(int.from_bytes(byte, "big"))
  37. else:
  38. print("text file format detected. parsing.")
  39. with open(sys.argv[n + 1]) as f:
  40. lines = f.readlines()
  41. for line in lines:
  42. nums = line.split()
  43. for r in nums:
  44. frame.append(int(r, 16))
  45. print("frame length: " + str(len(frame)))
  46. row_len = math.sqrt(len(frame))
  47. print("row length: " + str(row_len))
  48. row_len = int(row_len)
  49. frame2d = []
  50. for i in range(0, row_len):
  51. row = []
  52. for j in range(0, row_len):
  53. row.append(frame[i * row_len + j])
  54. frame2d.append(row)
  55. im = axes[n].imshow(frame2d, vmin=0, vmax=0xFF, cmap='plasma')
  56. axes[n].set_title(sys.argv[n + 1], fontsize=18)
  57. fig.colorbar(im, ax=axes, label='Value Range')
  58. plt.suptitle('Pan and Zoom on colorbar to adjust', fontsize=10)
  59. plt.show()