parameters: (self, gt, input_size = 512, random_scale = np.array([0.5, 1, 2.0, 3.0]),
                          background_ratio = 3. / 8)
docstring: :param gt: iamge path (str), wordBBoxes (2 * 4 * num_words), transcripts (multiline)
  
          :return:
function: def __transform(self, gt, input_size = 512, random_scale = np.array([0.5, 1, 2.0, 3.0]),
                          background_ratio = 3. / 8):
          '''
  
          :param gt: iamge path (str), wordBBoxes (2 * 4 * num_words), transcripts (multiline)
  
          :return:
          '''
  
          imagePath, wordBBoxes, transcripts = gt
          im = cv2.imread(imagePath.as_posix())
          #wordBBoxes = np.expand_dims(wordBBoxes, axis = 2) if (wordBBoxes.ndim == 2) else wordBBoxes
          #_, _, numOfWords = wordBBoxes.shape
          numOfWords = len(wordBBoxes)
          text_polys = wordBBoxes  # num_words * 8
          transcripts = [word for line in transcripts for word in line.split()]
          text_tags = [True if(tag == '*' or tag == '###') else False for tag in transcripts] # ignore '###'
  
          if numOfWords == len(transcripts):
              h, w, _ = im.shape
              text_polys, text_tags = check_and_validate_polys(text_polys, text_tags, (h, w))
  
              rd_scale = np.random.choice(random_scale)
              im = cv2.resize(im, dsize = None, fx = rd_scale, fy = rd_scale)
              text_polys *= rd_scale
  
              # print rd_scale
              # random crop a area from image
              if np.random.rand() < background_ratio:
                  # crop background
                  im, text_polys, text_tags = crop_area(im, text_polys, text_tags, crop_background = True)
                  if text_polys.shape[0] > 0:
                      # cannot find background
                      raise TypeError('cannot find background')
                  # pad and resize image
                  new_h, new_w, _ = im.shape
                  max_h_w_i = np.max([new_h, new_w, input_size])
                  im_padded = np.zeros((max_h_w_i, max_h_w_i, 3), dtype = np.uint8)
                  im_padded[:new_h, :new_w, :] = im.copy()
                  im = cv2.resize(im_padded, dsize = (input_size, input_size))
                  score_map = np.zeros((input_size, input_size), dtype = np.uint8)
                  geo_map_channels = 5
                  #                     geo_map_channels = 5 if FLAGS.geometry == 'RBOX' else 8
                  geo_map = np.zeros((input_size, input_size, geo_map_channels), dtype = np.float32)
                  training_mask = np.ones((input_size, input_size), dtype = np.uint8)
              else:
                  im, text_polys, text_tags = crop_area(im, text_polys, text_tags, crop_background = False)
                  if text_polys.shape[0] == 0:
                      raise TypeError('cannot find background')
                  h, w, _ = im.shape
  
                  # pad the image to the training input size or the longer side of image
                  new_h, new_w, _ = im.shape
                  max_h_w_i = np.max([new_h, new_w, input_size])
                  im_padded = np.zeros((max_h_w_i, max_h_w_i, 3), dtype = np.uint8)
                  im_padded[:new_h, :new_w, :] = im.copy()
                  im = im_padded
                  # resize the image to input size
                  new_h, new_w, _ = im.shape
                  resize_h = input_size
                  resize_w = input_size
                  im = cv2.resize(im, dsize = (resize_w, resize_h))
                  resize_ratio_3_x = resize_w / float(new_w)
                  resize_ratio_3_y = resize_h / float(new_h)
                  text_polys[:, :, 0] *= resize_ratio_3_x
                  text_polys[:, :, 1] *= resize_ratio_3_y
                  new_h, new_w, _ = im.shape
                  score_map, geo_map, training_mask = generate_rbox((new_h, new_w), text_polys, text_tags)
  
              # predict 出来的feature map 是 128 * 128， 所以 gt 需要取 /4 步长
              images = im[:, :, ::-1].astype(np.float32)  # bgr -> rgb
              score_maps = score_map[::4, ::4, np.newaxis].astype(np.float32)
              geo_maps = geo_map[::4, ::4, :].astype(np.float32)
              training_masks = training_mask[::4, ::4, np.newaxis].astype(np.float32)
  
              return images, score_maps, geo_maps, training_masks, transcripts
          else:
              raise TypeError('Number of bboxes is inconsist with number of transcripts ')
function_tokens: def __transform ( self , gt , input_size = 512 , random_scale = np . array ( [ 0.5 , 1 , 2.0 , 3.0 ] ) , background_ratio = 3. / 8 ) : imagePath , wordBBoxes , transcripts = gt im = cv2 . imread ( imagePath . as_posix ( ) ) #wordBBoxes = np.expand_dims(wordBBoxes, axis = 2) if (wordBBoxes.ndim == 2) else wordBBoxes #_, _, numOfWords = wordBBoxes.shape numOfWords = len ( wordBBoxes ) text_polys = wordBBoxes # num_words * 8 transcripts = [ word for line in transcripts for word in line . split ( ) ] text_tags = [ True if ( tag == '*' or tag == '###' ) else False for tag in transcripts ] # ignore '###' if numOfWords == len ( transcripts ) : h , w , _ = im . shape text_polys , text_tags = check_and_validate_polys ( text_polys , text_tags , ( h , w ) ) rd_scale = np . random . choice ( random_scale ) im = cv2 . resize ( im , dsize = None , fx = rd_scale , fy = rd_scale ) text_polys *= rd_scale # print rd_scale # random crop a area from image if np . random . rand ( ) < background_ratio : # crop background im , text_polys , text_tags = crop_area ( im , text_polys , text_tags , crop_background = True ) if text_polys . shape [ 0 ] > 0 : # cannot find background raise TypeError ( 'cannot find background' ) # pad and resize image new_h , new_w , _ = im . shape max_h_w_i = np . max ( [ new_h , new_w , input_size ] ) im_padded = np . zeros ( ( max_h_w_i , max_h_w_i , 3 ) , dtype = np . uint8 ) im_padded [ : new_h , : new_w , : ] = im . copy ( ) im = cv2 . resize ( im_padded , dsize = ( input_size , input_size ) ) score_map = np . zeros ( ( input_size , input_size ) , dtype = np . uint8 ) geo_map_channels = 5 #                     geo_map_channels = 5 if FLAGS.geometry == 'RBOX' else 8 geo_map = np . zeros ( ( input_size , input_size , geo_map_channels ) , dtype = np . float32 ) training_mask = np . ones ( ( input_size , input_size ) , dtype = np . uint8 ) else : im , text_polys , text_tags = crop_area ( im , text_polys , text_tags , crop_background = False ) if text_polys . shape [ 0 ] == 0 : raise TypeError ( 'cannot find background' ) h , w , _ = im . shape # pad the image to the training input size or the longer side of image new_h , new_w , _ = im . shape max_h_w_i = np . max ( [ new_h , new_w , input_size ] ) im_padded = np . zeros ( ( max_h_w_i , max_h_w_i , 3 ) , dtype = np . uint8 ) im_padded [ : new_h , : new_w , : ] = im . copy ( ) im = im_padded # resize the image to input size new_h , new_w , _ = im . shape resize_h = input_size resize_w = input_size im = cv2 . resize ( im , dsize = ( resize_w , resize_h ) ) resize_ratio_3_x = resize_w / float ( new_w ) resize_ratio_3_y = resize_h / float ( new_h ) text_polys [ : , : , 0 ] *= resize_ratio_3_x text_polys [ : , : , 1 ] *= resize_ratio_3_y new_h , new_w , _ = im . shape score_map , geo_map , training_mask = generate_rbox ( ( new_h , new_w ) , text_polys , text_tags ) # predict 出来的feature map 是 128 * 128， 所以 gt 需要取 /4 步长 images = im [ : , : , : : - 1 ] . astype ( np . float32 ) # bgr -> rgb score_maps = score_map [ : : 4 , : : 4 , np . newaxis ] . astype ( np . float32 ) geo_maps = geo_map [ : : 4 , : : 4 , : ] . astype ( np . float32 ) training_masks = training_mask [ : : 4 , : : 4 , np . newaxis ] . astype ( np . float32 ) return images , score_maps , geo_maps , training_masks , transcripts else : raise TypeError ( 'Number of bboxes is inconsist with number of transcripts ' )