code: def convert_image_generator_to_recognizer_input(
      image_generator,
      max_string_length,
      target_width,
      target_height,
      margin=0,
  ):
      """Convert an image generator created by get_image_generator
      to (image, sentence) tuples for training a recognizer.
  
      Args:
          image_generator: An image generator created by get_image_generator
          max_string_length: The maximum string length to allow
          target_width: The width to warp lines into
          target_height: The height to warp lines into
          margin: The margin to apply around a single line.
      """
      while True:
          image, lines = next(image_generator)
          if len(lines) == 0:
              continue
          for line in lines:
              line = _strip_line(line[:max_string_length])
              if not line:
                  continue
              box, sentence = tools.combine_line(line)
  
              # remove multiple sequential spaces
              while "  " in sentence:
                  sentence = sentence.replace("  ", " ")
  
              crop = tools.warpBox(
                  image=image,
                  box=box,
                  target_width=target_width,
                  target_height=target_height,
                  margin=margin,
                  skip_rotate=True,
              )
              yield crop, sentence
  
imports: import os
  import math
  import glob
  import typing
  import random
  import zipfile
  import string
  import itertools
  import cv2
  import tqdm
  import numpy
  import essential_generators
  import PIL.Image
  import PIL.ImageDraw
  import PIL.ImageFont
  import fontTools.ttLib
  from .None import tools
label_desc: Use image node_id 10 for calling a global function with example usage: convert_image_generator_to_recognizer_input(image_generator, max_string_length, target_width, target_height, margin) without return types