code: def resize_pad(img: np.ndarray, size: tuple):
      h, w, c = img.shape
      src = np.array(
          [
              [0, 0],  # 原坐标系中图像左上角点
              [w - 1, 0],  # 原坐标系中图像右上角点
              [0, h - 1],
          ],  # 原坐标系中图像左下角点
          dtype=np.float32,
      )
      dst = np.zeros((3, 2), dtype=np.float32)
      if h / w > size[0] / size[1]:
          # 需要在w方向padding
          wi = size[0] * (w / h)
          pad_w = (size[1] - wi) / 2
          dst[0, :] = [pad_w - 1, 0]  # 目标坐标系中图像左上角点
          dst[1, :] = [size[1] - pad_w - 1, 0]  # 目标坐标系中图像右上角点
          dst[2, :] = [pad_w - 1, size[0] - 1]  # 目标坐标系中图像左下角点
      else:
          # 需要在h方向padding
          hi = size[1] * (h / w)
          pad_h = (size[0] - hi) / 2
          dst[0, :] = [0, pad_h - 1]  # 目标坐标系中图像左上角点
          dst[1, :] = [size[1] - 1, pad_h - 1]  # 目标坐标系中图像右上角点
          dst[2, :] = [0, size[0] - pad_h - 1]  # 目标坐标系中图像左下角点
  
      trans = cv2.getAffineTransform(src, dst)  # 计算正向仿射变换矩阵
      # 对图像进行仿射变换
      resize_img = cv2.warpAffine(
          img, trans, size[::-1], flags=cv2.INTER_LINEAR  # w, h
      )
      # import matplotlib.pyplot as plt
      # plt.imshow(resize_img)
      # plt.show()
  
      dst /= 4  # 网络预测的heatmap尺寸是输入图像的1/4
      reverse_trans = cv2.getAffineTransform(
          dst, src
      )  # 计算逆向仿射变换矩阵，方便后续还原
  
      return resize_img, reverse_trans
  
imports: import math
  import random
  from typing import Tuple
  import cv2
  import numpy
  import torch
  from torchvision.transforms import functional
  import matplotlib.pyplot
label_desc: Use image node_id 7 for calling a global function with example usage: resize_pad(img, size) and returns: resize_img,  reverse_trans