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):
          for j in range(i, -1, -1):
              if abs(_boxes[j + 1][0][1] - _boxes[j][0][1]) < 10 and (
                  _boxes[j + 1][0][0] < _boxes[j][0][0]
              ):
                  tmp = _boxes[j]
                  _boxes[j] = _boxes[j + 1]
                  _boxes[j + 1] = tmp
              else:
                  break
      return _boxes
  
imports: import os
  import sys
  import subprocess
  import cv2
  import copy
  import numpy
  import json
  import time
  import logging
  from PIL import Image
  import tools.infer.utility
  import tools.infer.predict_rec
  import tools.infer.predict_det
  import tools.infer.predict_cls
  from ppocr.utils.utility import get_image_file_list, check_and_read
  from ppocr.utils.logging import get_logger
  from tools.infer.utility import draw_ocr_box_txt, get_rotate_crop_image, get_minarea_rect_crop
label_desc: Use image node_id 1 for calling a global function with example usage: sorted_boxes(dt_boxes) and returns: _boxes