code: def sorted_boxes(dt_boxes):
      """
      Sort text boxes in order from top to bottom, left to right
      args:
          dt_boxes(array):detected text boxes with shape [4, 2]
      return:
          sorted boxes(array) with shape [4, 2]
      """
      num_boxes = dt_boxes.shape[0]
      sorted_boxes = sorted(dt_boxes, key=lambda x: (x[0][1], x[0][0]))
      _boxes = list(sorted_boxes)
  
      for i in range(num_boxes - 1):
          if abs(_boxes[i + 1][0][1] - _boxes[i][0][1]) < 10 and (
              _boxes[i + 1][0][0] < _boxes[i][0][0]
          ):
              tmp = _boxes[i]
              _boxes[i] = _boxes[i + 1]
              _boxes[i + 1] = tmp
      return _boxes
  
file_path: PaddleHub/modules/image/text_recognition/chinese_ocr_db_crnn_mobile/utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import base64
  import math
  from io import BytesIO
  import cv2
  import numpy
  from PIL import Image
  from PIL import ImageDraw
  from PIL import ImageFont
label_desc: Use image node_id 6 for calling a global function with example usage: sorted_boxes(dt_boxes) and returns: _boxes