class_docstr: A general geometric augmentation tool for text images in the CVPR 2020
  paper "Learn to Augment: Joint Data Augmentation and Network Optimization
  for Text Recognition". It applies distortion, stretching, and perspective
  transforms to an image.
  
  This implementation is adapted from
  https://github.com/RubanSeven/Text-Image-Augmentation-python/blob/master/augment.py  # noqa
  
  TODO: Split this transform into three transforms.
  
  Required Keys:
  
  - img
  
  Modified Keys:
  
  - img
  - img_shape
class_docstr_tok: ["A","general","geometric","augmentation","tool","for","text","images","in","the","CVPR","2020","paper","``","Learn","to","Augment",":","Joint","Data","Augmentation","and","Network","Optimization","for","Text","Recognition","''",".","It","applies","distortion",",","stretching",",","and","perspective","transforms","to","an","image",".","This","implementation","is","adapted","from","https",":","\/\/github.com\/RubanSeven\/Text-Image-Augmentation-python\/blob\/master\/augment.py","#","noqa","TODO",":","Split","this","transform","into","three","transforms",".","Required","Keys",":","-","img","Modified","Keys",":","-","img","-","img_shape"]
docstr: Image perspective transformation.
  
  Args:
      img (np.ndarray): The image.
      segment (int): The number of segments to divide the image along
          the width. Defaults to 4.
docstr_tok: ["Image","perspective","transformation",".","Args",":","img","(","np.ndarray",")",":","The","image",".","segment","(","int",")",":","The","number","of","segments","to","divide","the","image","along","the","width",".","Defaults","to","4","."]
code: def tia_perspective(self, img: np.ndarray) -> np.ndarray:
      """Image perspective transformation.
  
      Args:
          img (np.ndarray): The image.
          segment (int): The number of segments to divide the image along
              the width. Defaults to 4.
      """
      img_h, img_w = img.shape[:2]
  
      thresh = img_h // 2
  
      src_pts = list()
      dst_pts = list()
  
      src_pts.append([0, 0])
      src_pts.append([img_w, 0])
      src_pts.append([img_w, img_h])
      src_pts.append([0, img_h])
  
      dst_pts.append([0, np.random.randint(thresh)])
      dst_pts.append([img_w, np.random.randint(thresh)])
      dst_pts.append([img_w, img_h - np.random.randint(thresh)])
      dst_pts.append([0, img_h - np.random.randint(thresh)])
  
      dst = self.warp_mls(img, src_pts, dst_pts, img_w, img_h)
  
      return dst
  
imports: import math
  import random
  from typing import Dict, List, Optional, Tuple
  import cv2
  import mmcv
  import numpy
  from mmcv.transforms.base import BaseTransform
  from mmcv.transforms.utils import cache_randomness
  from mmocr.registry import TRANSFORMS
label_desc: Use image node_id 5 for calling the TextRecogGeneralAug obj's underlying member method code with example usage: obj.tia_perspective(img) and returns: dst