code: def stitch_boxes_into_lines(
      boxes, max_x_dist=10, min_y_overlap_ratio=0.8
  ):
      # TODO Check if it should be deleted after ocr.py refactored
      """Stitch fragmented boxes of words into lines.
  
      Note: part of its logic is inspired by @Johndirr
      (https://github.com/faustomorales/keras-ocr/issues/22)
  
      Args:
          boxes (list): List of ocr results to be stitched
          max_x_dist (int): The maximum horizontal distance between the closest
                      edges of neighboring boxes in the same line
          min_y_overlap_ratio (float): The minimum vertical overlapping ratio
                      allowed for any pairs of neighboring boxes in the same line
  
      Returns:
          merged_boxes(list[dict]): List of merged boxes and texts
      """
  
      if len(boxes) <= 1:
          return boxes
  
      merged_boxes = []
  
      # sort groups based on the x_min coordinate of boxes
      x_sorted_boxes = sorted(
          boxes, key=lambda x: np.min(x["box"][::2])
      )
      # store indexes of boxes which are already parts of other lines
      skip_idxs = set()
  
      i = 0
      # locate lines of boxes starting from the leftmost one
      for i in range(len(x_sorted_boxes)):
          if i in skip_idxs:
              continue
          # the rightmost box in the current line
          rightmost_box_idx = i
          line = [rightmost_box_idx]
          for j in range(i + 1, len(x_sorted_boxes)):
              if j in skip_idxs:
                  continue
              if is_on_same_line(
                  x_sorted_boxes[rightmost_box_idx]["box"],
                  x_sorted_boxes[j]["box"],
                  min_y_overlap_ratio,
              ):
                  line.append(j)
                  skip_idxs.add(j)
                  rightmost_box_idx = j
  
          # split line into lines if the distance between two neighboring
          # sub-lines' is greater than max_x_dist
          lines = []
          line_idx = 0
          lines.append([line[0]])
          rightmost = np.max(x_sorted_boxes[line[0]]["box"][::2])
          for k in range(1, len(line)):
              curr_box = x_sorted_boxes[line[k]]
              dist = np.min(curr_box["box"][::2]) - rightmost
              if dist > max_x_dist:
                  line_idx += 1
                  lines.append([])
              lines[line_idx].append(line[k])
              rightmost = max(rightmost, np.max(curr_box["box"][::2]))
  
          # Get merged boxes
          for box_group in lines:
              merged_box = {}
              merged_box["text"] = " ".join(
                  [x_sorted_boxes[idx]["text"] for idx in box_group]
              )
              x_min, y_min = float("inf"), float("inf")
              x_max, y_max = float("-inf"), float("-inf")
              for idx in box_group:
                  x_max = max(
                      np.max(x_sorted_boxes[idx]["box"][::2]), x_max
                  )
                  x_min = min(
                      np.min(x_sorted_boxes[idx]["box"][::2]), x_min
                  )
                  y_max = max(
                      np.max(x_sorted_boxes[idx]["box"][1::2]), y_max
                  )
                  y_min = min(
                      np.min(x_sorted_boxes[idx]["box"][1::2]), y_min
                  )
              merged_box["box"] = [
                  x_min,
                  y_min,
                  x_max,
                  y_min,
                  x_max,
                  y_max,
                  x_min,
                  y_max,
              ]
              merged_boxes.append(merged_box)
  
      return merged_boxes
  
file_path: mmocr/mmocr/utils/bbox_utils.py
imports: from typing import List, Tuple
  import numpy
  from shapely.geometry import LineString, Point
  from mmocr.utils.check_argument import is_type_list
  from mmocr.utils.point_utils import point_distance, points_center
  from mmocr.utils.typing_utils import ArrayLike
label_desc: Use image node_id 5 for calling a global function with example usage: stitch_boxes_into_lines(boxes, max_x_dist, min_y_overlap_ratio) and returns: merged_boxes, boxes