ioImg.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import re
  2. import time
  3. import cv2
  4. import numpy as np
  5. def showHex(txt, i):
  6. time, unit, val = txt.strip().split(" ")
  7. time = int(time)
  8. for x in ["s", "ms", "us", "ns", "ps", "fs"]:
  9. if unit == x:
  10. break
  11. time /= 1000.0
  12. if re.match(r'[01]{32}', val, re.M):
  13. num = int(val, 2)
  14. print("{:6d} {:8.0f} ns {} {:08X}".format(i, time * 10**9, val, num))
  15. else:
  16. print("{:6d} {:8.0f} ns {}".format(i, time * 10**9, val))
  17. size = 224
  18. kernel = 5
  19. border = int(kernel/2)
  20. sizeWithBorder = size+2*border
  21. pixels = sizeWithBorder**2
  22. imageIn = np.zeros((sizeWithBorder,sizeWithBorder,1), np.uint8)
  23. imageOut = np.zeros((sizeWithBorder,sizeWithBorder,1), np.uint8)
  24. def setPixel(img, txt, i, input):
  25. time, unit, val = txt.strip().split(" ")
  26. time = int(time)
  27. for x in ["s", "ms", "us", "ns", "ps", "fs"]:
  28. if unit == x:
  29. break
  30. time /= 1000.0
  31. if re.match(r'[01]{32}', val, re.M):
  32. num = int(val, 2)
  33. if num > 0x7FFFFFFF:
  34. num = num - 0xFFFFFFFF - 1
  35. if not input:
  36. num = num/25
  37. x = i % sizeWithBorder
  38. y = int(i / sizeWithBorder) % sizeWithBorder
  39. img[y][x] = num
  40. def main():
  41. with open("workspace/complete-bd/complete-bd.sim/sim_1/behav/xsim/input.txt", "r") as inFile:
  42. #print("Input:")
  43. i = 0
  44. for line in inFile:
  45. if i < 3 or i >= 3 + pixels:
  46. showHex(line, i)
  47. else:
  48. setPixel(imageIn, line, i-3, True)
  49. i += 1
  50. with open("workspace/complete-bd/complete-bd.sim/sim_1/behav/xsim/output.txt", "r") as outFile:
  51. #print("Output:")
  52. i = 0
  53. for line in outFile:
  54. if i < 3 or i >= 3 + pixels:
  55. showHex(line, i)
  56. else:
  57. setPixel(imageOut, line, i-3, False)
  58. i += 1
  59. #while True:
  60. #print("\n\n\n\n")
  61. main()
  62. cv2.imshow('send', imageIn)
  63. cv2.imshow('recv', imageOut)
  64. cv2.waitKey(0)