| 5 | |
| 6 | |
| 7 | def plot_tensor(window_name: str, tensor: np.ndarray, coord_highlight: tuple[int, int] = None): |
| 8 | font_size = 48 |
| 9 | image = np.zeros((tensor.shape[1] * font_size, tensor.shape[0] * font_size, 3), dtype=np.uint8) |
| 10 | |
| 11 | for y in range(tensor.shape[1]): |
| 12 | for x in range(tensor.shape[0]): |
| 13 | if coord_highlight and x == coord_highlight[1] and y == coord_highlight[0]: |
| 14 | cv2.putText( |
| 15 | image, str(int(tensor[y, x])), (x * font_size, int((y + 0.8) * font_size)), |
| 16 | cv2.FONT_HERSHEY_TRIPLEX, 1., (127, 127, 255)) |
| 17 | else: |
| 18 | cv2.putText( |
| 19 | image, str(int(tensor[y, x])), (x * font_size, int((y + 0.8) * font_size)), |
| 20 | cv2.FONT_HERSHEY_TRIPLEX, 1., (255, 255, 255)) |
| 21 | |
| 22 | cv2.imshow(window_name, image) |
| 23 | |
| 24 | |
| 25 | def main(): |