Нема описа
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 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env python
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import sys
  5. import math
  6. import os
  7. if len(sys.argv) < 2:
  8. print("Usage:")
  9. print(" " + sys.argv[0] + " filename [...]")
  10. sys.exit(0)
  11. fig, axes = plt.subplots(1, len(sys.argv) - 1, figsize=(15, 5))
  12. # support one or multiple files
  13. if not isinstance(axes, np.ndarray):
  14. axes = [axes]
  15. for n in range(0, len(sys.argv) - 1):
  16. print("reading " + sys.argv[n + 1])
  17. frame = []
  18. if os.path.getsize(sys.argv[n + 1]) == 1296:
  19. print("binary file format detected. parsing.")
  20. with open(sys.argv[n + 1], "rb") as f:
  21. while (byte := f.read(1)):
  22. frame.append(int.from_bytes(byte, "big"))
  23. else:
  24. print("text file format detected. parsing.")
  25. with open(sys.argv[n + 1]) as f:
  26. lines = f.readlines()
  27. for line in lines:
  28. nums = line.split()
  29. for r in nums:
  30. frame.append(int(r, 16))
  31. print("frame length: " + str(len(frame)))
  32. row_len = math.sqrt(len(frame))
  33. print("row length: " + str(row_len))
  34. row_len = int(row_len)
  35. frame2d = []
  36. for i in range(0, row_len):
  37. row = []
  38. for j in range(0, row_len):
  39. row.append(frame[i * row_len + j])
  40. frame2d.append(row)
  41. im = axes[n].imshow(frame2d, vmin=0, vmax=0xFF, cmap='plasma')
  42. axes[n].set_title(sys.argv[n + 1], fontsize=18)
  43. fig.colorbar(im, ax=axes, label='Value Range')
  44. plt.suptitle('Pan and Zoom on colorbar to adjust', fontsize=10)
  45. plt.show()